xstar
asked on
Capturing Windows Text
Hi,
I am trying to capture other windows text (eg. notepad) but I can only get the handle to the window but not its text. I tried using CWnd functions (GetWindow, GetNextWindow..etc) to get the object/child in the main window but it is not able to get the correct object. I can only get the handle to buttons, edit boxes and static objects. For notepad, it can only detect the main window and another child window. Is there a way to get the text inside the notepad?
Thanks.
I am trying to capture other windows text (eg. notepad) but I can only get the handle to the window but not its text. I tried using CWnd functions (GetWindow, GetNextWindow..etc) to get the object/child in the main window but it is not able to get the correct object. I can only get the handle to buttons, edit boxes and static objects. For notepad, it can only detect the main window and another child window. Is there a way to get the text inside the notepad?
Thanks.
If you're talknig aobut the text inside the notepad opened file (an not the window title bar) you'll just have to find the first notepad child that is an edit box (has the classname "Edit" with GetClassName) and get its text through GetWindowText.
ASKER
Hi,
I can only detect one child item in the notepad and though it is a Edit object, GetWindowText always returns an empty string.
I can only detect one child item in the notepad and though it is a Edit object, GetWindowText always returns an empty string.
>GetWindowText always returns an empty string.
It shouldn't. Please post some code.
It shouldn't. Please post some code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Damn did it again
EM_GETLINE returns the number of chars copied to the buffer.
after
>> eol = SendMessage ( hChild, EM_GETLINE, i, (DWORD)(LPSTR)szBuf ) ; // ask for a specific line
you need to add
szBuf[eol] = '\0' ;
EM_GETLINE returns the number of chars copied to the buffer.
after
>> eol = SendMessage ( hChild, EM_GETLINE, i, (DWORD)(LPSTR)szBuf ) ; // ask for a specific line
you need to add
szBuf[eol] = '\0' ;
ASKER
Hi,
Thanks. I totally forgot about the multiline feature!
Thanks. I totally forgot about the multiline feature!
Glad to have been of assistence.
i.e.
Example
char szWindowText[256] ;
DWORD dwSize = 256 ;
GetWindowText ( hWnd, szWindowText, dwSize ) ;