Click to See Complete Forum and Search --> : GetWindowText fail


gamer150
January 24th, 2008, 06:11 PM
Whenever I use GetWindowText and pass a valid window handle, the function returns 0 (error). GetLastError() tells me it is an invalid window handle when i know it isn't... am i missing something?

Plasmator
January 24th, 2008, 08:08 PM
GetLastError() tells me it is an invalid window handle when i know it isn't... Are you completely sure that your handle is, indeed, valid? GLE usually doesn't lie.

VladimirF
January 25th, 2008, 01:22 PM
... am i missing something?Is it YOUR window?
What kind of window is it?
Does it have a caption?

Marc G
January 26th, 2008, 08:41 AM
You cannot use GetWindowText to get the text of child windows of other processes.

MikeAThon
January 26th, 2008, 11:48 AM
You cannot use GetWindowText to get the text of child windows of other processes.
That's not completely true. Although the documentation says this exactly, the real story is more complicated. See "The secret life of GetWindowText" at Raymond Chen's Old New Thing blog, http://blogs.msdn.com/oldnewthing/archive/2003/08/21/54675.aspx

To gamer150, try sending WM_GETTEXT using SendMessageTimeout(). Use SendMessageTimeout so that if the target application is hung, your application does not also become hung.

Mike

gamer150
January 31st, 2008, 09:29 AM
I was using the window handle returned from CreateWindow() and that wasn't working. It works now because instead I use GetDlgItem.