GetWindowText
-
Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?
CWnd\* cWnd; POINT pt; ::GetCursorPos(&pt); cWnd = WindowFromPoint(pt); CString strBuf; cWnd->GetWindowText(strBuf); MessageBox(strBuf);
Thanks Rob
-
Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?
CWnd\* cWnd; POINT pt; ::GetCursorPos(&pt); cWnd = WindowFromPoint(pt); CString strBuf; cWnd->GetWindowText(strBuf); MessageBox(strBuf);
Thanks Rob
I guess you can call
ChildWindowFromPoint
on thecWnd
retrieved, sort of like this (warning: didn't compile it):CWnd* cWnd;
POINT pt;
::GetCursorPos(&pt);
cWnd = WindowFromPoint(pt);
cWnd->ScreenToClient(&pt);
CWnd* cChildWnd = cWnd->ChildWindowFromPoint(pt);
CString strBuf;
cChildWnd->GetWindowText(strBuf);
MessageBox(strBuf);Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?
CWnd\* cWnd; POINT pt; ::GetCursorPos(&pt); cWnd = WindowFromPoint(pt); CString strBuf; cWnd->GetWindowText(strBuf); MessageBox(strBuf);
Thanks Rob
I think the better way is to use SendMessage and OnCopyData. 1. First you search your target window handle. 2. You send a WM_COPYDATA to target window. 3. Write in your target app a function to handlw WM_COPYDATA Code: char szWindowName[60]; // "Target App" is the target app main window caption CString szTargetWindowName = "Target App"; int nFound; int nLength = strlen(szTargetWindowName); HWND hSearchHandle; for(hSearchHandle=::GetWindow(::GetDesktopWindow(), GW_CHILD);hSearchHandle; hSearchHandle = ::GetWindow(hSearchHandle, GW_HWNDNEXT)) { ::GetWindowText(hSearchHandle, szWindowName, 58); szWindowName[nLength] = '\0'; nFound = lstrcmpi(szWindowName, szTargetWindowName); if(nFound == 0) { CWnd pCwnd; COPYDATASTRUCT cds; char myStr[60]; strcpy(myStr,"Lets go."); cds.dwData = 0; cds.lpData = myStr; cds.cbData = sizeof(myStr); LONG lResult; lResult = ::SendMessage(hSearchHandle, WM_COPYDATA,(WPARAM)&pCwnd.m_hWnd, (LPARAM)(COPYDATASTRUCT*)&cds); } } ----------------------------------------- Now in your target app: BOOL CAppADlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { MessageBox((char *)pCopyDataStruct->lpData); return CDialog::OnCopyData(pWnd, pCopyDataStruct); } Try it.
-
I think the better way is to use SendMessage and OnCopyData. 1. First you search your target window handle. 2. You send a WM_COPYDATA to target window. 3. Write in your target app a function to handlw WM_COPYDATA Code: char szWindowName[60]; // "Target App" is the target app main window caption CString szTargetWindowName = "Target App"; int nFound; int nLength = strlen(szTargetWindowName); HWND hSearchHandle; for(hSearchHandle=::GetWindow(::GetDesktopWindow(), GW_CHILD);hSearchHandle; hSearchHandle = ::GetWindow(hSearchHandle, GW_HWNDNEXT)) { ::GetWindowText(hSearchHandle, szWindowName, 58); szWindowName[nLength] = '\0'; nFound = lstrcmpi(szWindowName, szTargetWindowName); if(nFound == 0) { CWnd pCwnd; COPYDATASTRUCT cds; char myStr[60]; strcpy(myStr,"Lets go."); cds.dwData = 0; cds.lpData = myStr; cds.cbData = sizeof(myStr); LONG lResult; lResult = ::SendMessage(hSearchHandle, WM_COPYDATA,(WPARAM)&pCwnd.m_hWnd, (LPARAM)(COPYDATASTRUCT*)&cds); } } ----------------------------------------- Now in your target app: BOOL CAppADlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { MessageBox((char *)pCopyDataStruct->lpData); return CDialog::OnCopyData(pWnd, pCopyDataStruct); } Try it.
The target app is not mine (It's commercial software and I don't have the source code).. :( Basicly what I am trying to do is pull text from the Rich edit control on Yahoo! Messenger (The chat window. When you are talking to someone) and store the whole msg in a string.
-
Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?
CWnd\* cWnd; POINT pt; ::GetCursorPos(&pt); cWnd = WindowFromPoint(pt); CString strBuf; cWnd->GetWindowText(strBuf); MessageBox(strBuf);
Thanks Rob
GetWindowText will not retrieve the text in an edit control in another application (thread?). GetWindowText retrieves the caption from the window's internal data. Even with a lot of text, edit controls always have an empty string as its caption. The workaround is to send the edit control a WM_GETTEXT message (preferably using SendMessageTimeout) to retrieve the text. Peter O.
-
Hello, I am trying to pull text from inside a edit box on another application.. Here is what I have tried, this only pulls the windows title bar text.. any ideas on how i can pull text from with in a edit box on another app?
CWnd\* cWnd; POINT pt; ::GetCursorPos(&pt); cWnd = WindowFromPoint(pt); CString strBuf; cWnd->GetWindowText(strBuf); MessageBox(strBuf);
Thanks Rob