Skip to content

Latest commit

 

History

History
137 lines (85 loc) · 5.93 KB

nf-winuser-getwindowtextlengthw.md

File metadata and controls

137 lines (85 loc) · 5.93 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name req.apiset
NF:winuser.GetWindowTextLengthW
GetWindowTextLengthW function (winuser.h)
Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar). (Unicode)
GetWindowTextLength
GetWindowTextLength function [Windows and Messages]
GetWindowTextLengthW
_win32_GetWindowTextLength
_win32_getwindowtextlength_cpp
winmsg.getwindowtextlength
winui._win32_getwindowtextlength
winuser/GetWindowTextLength
winuser/GetWindowTextLengthW
winmsg\getwindowtextlength.htm
winmsg
VS|winui|~\winui\windowsuserinterface\windowing\windows\windowreference\windowfunctions\getwindowtextlength.htm
12/05/2018
GetWindowTextLength, GetWindowTextLength function [Windows and Messages], GetWindowTextLengthA, GetWindowTextLengthW, _win32_GetWindowTextLength, _win32_getwindowtextlength_cpp, winmsg.getwindowtextlength, winui._win32_getwindowtextlength, winuser/GetWindowTextLength, winuser/GetWindowTextLengthA, winuser/GetWindowTextLengthW
winuser.h
Windows.h
Windows
Windows 2000 Professional [desktop apps only]
Windows 2000 Server [desktop apps only]
GetWindowTextLengthW (Unicode) and GetWindowTextLengthA (ANSI)
User32.lib
User32.dll
Windows
19H1
GetWindowTextLengthW
winuser/GetWindowTextLengthW
c++
APIRef
kbSyntax
DllExport
User32.dll
Ext-MS-Win-NTUser-Window-l1-1-1.dll
Ext-MS-Win-NTUser-Window-l1-1-2.dll
ext-ms-win-ntuser-window-l1-1-3.dll
Ext-MS-Win-NTUser-Window-L1-1-0.dll
Ext-MS-Win-NTUser-Window-L1-1-4.dll
GetWindowTextLength
GetWindowTextLengthA
GetWindowTextLengthW
ext-ms-win-ntuser-window-l1-1-1 (introduced in Windows 8.1)

GetWindowTextLengthW function

-description

Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar). If the specified window is a control, the function retrieves the length of the text within the control. However, GetWindowTextLength cannot retrieve the length of the text of an edit control in another application.

-parameters

-param hWnd [in]

Type: HWND

A handle to the window or control.

-returns

Type: int

If the function succeeds, the return value is the length, in characters, of the text. Under certain conditions, this value might be greater than the length of the text (see Remarks).

If the window has no text, the return value is zero.

Function failure is indicated by a return value of zero and a GetLastError result that is nonzero.

Note

This function does not clear the most recent error information. To determine success or failure, clear the most recent error information by calling SetLastError with 0, then call GetLastError.

-remarks

If the target window is owned by the current process, GetWindowTextLength causes a WM_GETTEXTLENGTH message to be sent to the specified window or control.

Under certain conditions, the GetWindowTextLength function may return a value that is larger than the actual length of the text. This occurs with certain mixtures of ANSI and Unicode, and is due to the system allowing for the possible existence of double-byte character set (DBCS) characters within the text. The return value, however, will always be at least as large as the actual length of the text; you can thus always use it to guide buffer allocation. This behavior can occur when an application uses both ANSI functions and common dialogs, which use Unicode. It can also occur when an application uses the ANSI version of GetWindowTextLength with a window whose window procedure is Unicode, or the Unicode version of GetWindowTextLength with a window whose window procedure is ANSI. For more information on ANSI and ANSI functions, see Conventions for Function Prototypes.

To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function.

Note

The winuser.h header defines GetWindowTextLength as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

-see-also

CB_GETLBTEXT

Conceptual

GetWindowText

LB_GETTEXT

Other Resources

Reference

SetWindowText

WM_GETTEXT

WM_GETTEXTLENGTH

Windows