User32GetWindowText(IntPtr, StringBuilder, Int32) Method

Copies the text of the specified window's title bar (if it has one) into a buffer.

If the specified window is a control, the text of the control is copied.

GetWindowText(IntPtr, StringBuilder, Int32) cannot retrieve the text of a control in another application than the calling application.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("User32.dll", CharSet = CharSet.Unicode, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static int GetWindowText(
	IntPtr hWnd,
	StringBuilder lpString,
	int cch
)

Parameters

hWnd  IntPtr
A handle to the window or control containing the text.
lpString  StringBuilder
The buffer that will receive the text.

If the string is as long or longer than the buffer, the string is truncated and terminated with a null character.

cch  Int32
The maximum number of characters to copy to the buffer, including the null character.

If the text exceeds this limit, it is truncated.

Return Value

Int32
If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating null character.

If the window has no title bar or text, if the title bar is empty, or if the window or control handle is invalid, the return value is zero.

To get extended error information, call GetLastWin32Error.

Remarks

See Also