GetWindowText Function

Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

GetWindowText reads the text on the title bar of a window. This function works with any window, not just those in your application. The text is put into the string variable passed as lpString. The function returns the length of the string returned if successful, or 0 if an error occured.

hwnd
The handle of the window to read the title of.
lpString
String variable that receives the text of the title bar of the window.
cch
The length in characters of lpString.

Example:

' Display the text of the title bar of window Form1
Dim textlen As Long  ' receives length of text of title bar
Dim titlebar As String  ' receives the text of the title bar
Dim slength As Long  ' receives the length of the returned string

' Find out how many characters are in the window's title bar
textlen = GetWindowTextLength(Form1.hWnd)
titlebar = Space(textlen + 1)  ' make room in the buffer, allowing for the terminating null character
slength = GetWindowText(Form1.hWnd, titlebar, textlen + 1)  ' read the text of the window
titlebar = Left(titlebar, slength)  ' extract information from the buffer
Debug.Print "The title bar of the window: "; titlebar

Related Calls: GetWindowTextLength, SetWindowText
Category: Windows
Back to the index.


Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/g/getwindowtext.html