The GetDlgItemText function retrieves the title or text associated with a control in a dialog box.
Syntax
UINT GetDlgItemText(
HWND hDlg,
int nIDDlgItem,
LPTSTR lpString,
int nMaxCount
);
Parameters
- hDlg
-
[in] Handle to the dialog box that contains the control.
- nIDDlgItem
-
[in] Specifies the identifier of the control whose title or text is to be retrieved.
- lpString
-
[out] Pointer to the buffer to receive the title or text.
- nMaxCount
-
[in] Specifies the maximum length, in TCHARs, of the string to be copied to the buffer pointed to by lpString. If the length of the string, including the NULL character, exceeds the limit, the string is truncated.
Return Value
If the function succeeds, the return value specifies the number of TCHARs copied to the buffer, not including the terminating NULL character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
If the string is as long or longer than the buffer, the buffer will contain the truncated string with a terminating NULL character.
The GetDlgItemText function sends a WM_GETTEXT message to the control.
For the ANSI version of the function, the number of TCHARs is the number of bytes; for the Unicode version, it is the number of characters.
Windows 95/98/Me: GetDlgItemTextW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Example
For an example, see Creating a Modal Dialog Box.
Function Information
| Minimum DLL Version | user32.dll |
|---|
| Header | Declared in Winuser.h, include Windows.h |
|---|
| Import library | User32.lib |
|---|
| Minimum operating systems |
Windows 95, Windows NT 3.1 |
|---|
| Unicode | Implemented as
ANSI and Unicode versions. |
|---|
See Also