Thursday, July 02, 2015
    Search Web Link
Search Software
API Home » Window » GetWindowTextLength


Category: Window
Hits: 5987 Rating: GetWindowTextLength has been rated 2.98 by  618 users (2.98) votes 618
Rate: 1-star  2-stars  3-stars  4-stars  5-stars
E-mail this API to friend E-mail this Code to a friend  save Bookmark this VB API Function
API Explanation
GetWindowTextLength returns the length in characters of the text in a window's title bar. You can use this function in conjunction with GetWindowText to create a string just long enough to receive the title. If you do, be sure to make the string 1 character longer than the value the function returns to allow for the ending vbNullChar. The function returns 0 if an error occurs.

Parameter Information
Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long

The handle of the window to read the length of the title bar text.

' 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

Copyright © 2000 - 2013 Ex-designz. All rights reserved. Website Developed By Dexter Zafra of
Link to us | Advertisement | Contact us | Privacy Policy | Terms of use | Accessibility