Link to home
Start Free TrialLog in
Avatar of xstar
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.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Can you not just call GetWindowText with the handle of the window

i.e.

Example

char szWindowText[256] ;
DWORD dwSize = 256 ;

GetWindowText ( hWnd, szWindowText, dwSize ) ;
Avatar of nonubik
nonubik

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.
Avatar of xstar

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.
>GetWindowText always returns an empty string.
It shouldn't. Please post some code.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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' ;

Avatar of xstar

ASKER

Hi,

Thanks. I totally forgot about the multiline feature!
Glad to have been of assistence.