Send the WM_GETTEXT message to a window to retrieve that window's text. For regular windows, this text is the text displayed in the title bar caption area. The target window's text is copied to a text buffer supplied in the message parameters. The message is handled by the target window's default window procedure.
The message returns the number of characters retrieved, not counting the terminating null character.
When using SendMessage to send the WM_GETTEXT message, the ByVal keyword must be used in front of both the wParam and lParam parameters.
Const WM_GETTEXT = &HD
' This code is licensed according to the terms and conditions listed here.
' 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(Form1.hWnd, 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(Form1.hWnd, WM_GETTEXT, ByVal slength, ByVal wintext)
' Remove the terminating null and extra space from the buffer.
wintext = Left(wintext, retval)
' Display the result.
Debug.Print "Form1's title bar text is: "; wintext
GetWindowText, WM_GETTEXTLENGTH, WM_SETTEXT
Back to the Message list.
Back to the Reference section.
Last Modified: January 26, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/w/wm_gettext.html