-
February 7th, 2001, 07:06 PM
#1
API - WM_GETTEXT is failing to work correctly....
Hi-
I am using the postmessage function and the WM_GETTEXT constant to obtain the text from a window but it doesnt want to work with this one window. The coding I have works on other windows but for some reason I can not get the text from this particular window. It is not a password box or anything, its just a window. I checked to make sure it was enabled and it is enabled. Does anyone know how I can get the text from the window or have any ideas why I can't get the text? Thanks.
Code segment I am using:
' Display the title bar text of window Form1 by sending the
' appropriate messages to it.
Dim wintext as string ' receives the copied text from the target window
Dim slength as Long ' length of the window text
Dim retval as Long ' return value of message
' First, determine how much space is necessary for the buffer.
' (1 is added for the terminating null character.)
slength = SendMessage(wnd, WM_GETTEXTLENGTH, byval CLng(0), byval CLng(0)) + 1
' Make enough room in the buffer to receive the text.
wintext = Space(slength)
' Copy the target window's text into the buffer.
retval = SendMessage(wnd, WM_GETTEXT, byval slength, byval wintext)
' Remove the terminating null and extra space from the buffer.
wintext = Left(wintext, retval)
' Display the result.
List1.AddItem wintext
FaRd0wN
-
February 8th, 2001, 10:33 AM
#2
Re: API - WM_GETTEXT is failing to work correctly....
I'd use GetWindowText instead;
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (byval hwnd as Long, byval lpString as string, byval cch as Long) as Long
but chances are an API error is occuring - so this probably won't make a difference.
After calling any API call, check the VB intrinsic error's LastDllError member i.e.
retval = SendMessage(wnd, WM_GETTEXT, byval slength, byval wintext)
If Err.LastDllError = 0 then
wintext = Left(wintext, retval)
else
'\\ An error has occured....
End If
I have written an article describing how you convert this error number into a sensible message at:
http://www.themestream.com/articles/305636.html
HTH,
D.
------------------------------------------------
Ex Datis: Duncan Jones
Merrion Computing Ltd
Dublin, Ireland
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|