Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Why not GetWindowText()?
|
Posted: Dec 18, 2003 5:03 PM
|
|
Do you know there is a GetWindowText() API call?
In any event, here is a homemade GetWindowText(), which uses SendMessage() and WM_GETTEXT, as you requested (it is also using the string object from STL:
std::string GetWindowText( HWND wnd ) { std::string text; WPARAM length = SendMessage( wnd, WM_GETTEXTLENGTH, 0, 0 ); if( length > 0 ) { char *buffy = new char [length+1];
LRESULT got = SendMessage( wnd, WM_GETTEXT, length+1, (LPARAM)buffy ); if( (LRESULT)length == got ) text = buffy;
delete [] buffy; } return text; }
(sorry about the lack of formatting; it looks like the tags support in the forum is temporarily not working)
|
|