WM_SETTEXT message
Applies to: desktop apps only
Sets the text of a window.
#define WM_SETTEXT 0x000C
Parameters
- wParam
-
This parameter is not used.
- lParam
-
A pointer to a null-terminated string that is the window text.
Return value
Type: LRESULT
The return value is TRUE if the text is set. It is FALSE (for an edit control), LB_ERRSPACE (for a list box), or CB_ERRSPACE (for a combo box) if insufficient space is available to set the text in the edit control. It is CB_ERR if this message is sent to a combo box without an edit control.
Remarks
The DefWindowProc function sets and displays the window text. For an edit control, the text is the contents of the edit control. For a combo box, the text is the contents of the edit-control portion of the combo box. For a button, the text is the button name. For other windows, the text is the window title.
This message does not change the current selection in the list box of a combo box. An application should use the CB_SELECTSTRING message to select the item in a list box that matches the text in the edit control.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
See also
- Reference
- DefWindowProc
- WM_GETTEXT
- Conceptual
- Windows
- Other Resources
- CB_SELECTSTRING
Send comments about this topic to Microsoft
Build date: 2/3/2012
If the String pointer passed to WM_SETTEXT or to SetWindowText() is not at an even address in memory the funtion/message will not set the WindowText and return TRUE.
___________________________________
BYTE* u8_Mem = (BYTE*)GlobalAlloc(GMEM_FIXED, 100) + 1;
WCHAR* u16_Text = (WCHAR*)u8_Mem;
wcscpy(u16_Text, L"Hello World");
BOOL b_Ret = SetWindowTextW(h_Wnd, u16_Text);
___________________________________
If you remove the "+1" in the first line the code will work.
This is absurd.
It seems that Windows assumes that a String pointer that has not an even address is an invalid pointer.
I think Microsoft should use more intelligent ways to check memory addresses.
At least the function should return FALSE and an error code in GetLastError() indicating that the function failed.
I observed this only on Windows 7 - 64 Bit version no matter if the application was compiled as 32 Bit or 64 Bit.
If you use structs that are BYTE aligned and contain strings you may easily run into this problem.
- 5/22/2012
- ElmueSoft
Declarations:
Private Const WM_SETTEXT As Integer = &HC
Declare Auto Function SendMessage Lib "user32.dll" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wparam As Integer, _
ByVal lparam As System.Text.StringBuilder) As IntPtr
Usage:
hr= SendMessage(childhandle, WM_SETTEXT, log.ToString.Length, log)
where, log is System.Text.StringBuilder which contains log information we want to show
- 10/6/2010
- paste.deepak
example:
TCHAR tc[1000];
_stprintf(tc, TEXT("Mary had a little lamb\r\nWhose Fleece was white as snow\r\nEverywhere that Mary went\r\nThe lamb was sure to go"));
SendMessage(editHwnd, WM_SETTEXT, 0, (LPARAM)tc); // for Win32 windows
SendMessage(GetDlgItem(hDlg, IDC_EDIT1), WM_SETTEXT, 0, (LPARAM)tc); // dialog example