windows_programming_notes.nbk: Home | Index | Next Page: WM_GETTEXTLENGTH | Previous Page: WM_GETMINMAXINFO


 WM_GETTEXT

An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.

Syntax

To send this message, call the SendMessage function as follows.

    lResult = SendMessage(         // returns LRESULT in lResult     
        (HWND)   hWndControl,      // handle to destination control     
        (UINT)   WM_GETTEXT,       // message ID     
        (WPARAM) wParam,           // = (WPARAM) () wParam;    
        (LPARAM) lParam            // = (LPARAM) () lParam; 
    );   

Parameters

Return Value

The return value is the number of TCHARs copied, not including the terminating null character.

Remarks

The DefWindowProc function copies the text associated with the window into the specified buffer and returns the number of characters copied. Note, for non-text static controls this gives you the text with which the control was originally created, that is, the ID number. However, it gives you the ID of the non-text static control as originally created. That is, if you subsequently used a STM_SETIMAGE to change it the original ID would still be returned.

For an edit control, the text to be copied is the content of the edit control. For a combo box, the text is the content of the edit control (or static-text) portion of the combo box. For a button, the text is the button name. For other windows, the text is the window title. To copy the text of an item in a list box, an application can use the LB_GETTEXT message.

When the WM_GETTEXT message is sent to a static control with the SS_ICON style, a handle to the icon will be returned in the first four bytes of the buffer pointed to by lParam. This is true only if the WM_SETTEXT message has been used to set the icon.

Rich Edit: If the text to be copied exceeds 64K, use either the EM_STREAMOUT or EM_GETSELTEXT message.

Windows 2000/XP: Sending a WM_GETTEXT message to a non-text static control, such as a static bitmap or static icon control, does not return a string value. Instead, it returns zero. In addition, in previous versions of Microsoft Windows and Microsoft Windows NT, applications could send a WM_GETTEXT message to a non-text static control to retrieve the control's ID. To retrieve a control's ID in Windows 2000/XP, applications can use GetWindowLong passing GWL_ID as the index value or GetWindowLongPtr using GWLP_ID.

Message Information


windows_programming_notes.nbk: Home | Index | Next Page: WM_GETTEXTLENGTH | Previous Page: WM_GETMINMAXINFO


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time