Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
Platforms
- Windows 95: Supported.
- Windows 98: Supported.
- Windows NT: Requires Windows NT 3.1 or later.
- Windows 2000: Supported.
- Windows CE: Requires Windows CE 1.0 or later.
Description & Usage
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.
Return Value
The message returns the number of characters retrieved, not counting the terminating null character.
Visual Basic-Specific Issues
When using SendMessage to send the WM_GETTEXT message, the ByVal keyword must be used in front of both the wParam and lParam parameters.
Parameters
- wParam
- The number of characters to copy from the target window's text, including the necessary terminating null character.
- lParam
- The string which receives the first wParam characters (minus one for the null) of the target window's text.
Constant Definitions
Const WM_GETTEXT = &HD
Example
' 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
See Also
GetWindowText, WM_GETTEXTLENGTH, WM_SETTEXT
Category
Windows
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