Control Messages

A parent window or other windows send control messages to direct a control to perform specific tasks. The window procedure processes these messages and carries out the requested action.

Control messages can be predefined or application defined. Windows has several predefined messages, such as WM_GETTEXT and WM_GETDLGCODE, that it sends to controls. These messages typically correspond to window-management functions that carry out actions on windows. In general, the window procedure for an application-defined control should process any predefined control message in the following table if the message affects the operation of the control.

Message Recommendation
WM_GETDLGCODE Process if the control uses the ENTER, ESC, TAB, or arrow keys. The IsDialogMessage function sends this message to controls in a dialog box to determine whether to process the keys or pass them to the control.
WM_GETFONT Process if the WM_SETFONT message is also processed.
WM_GETTEXT Process if the control text is not the same as the title specified by the CreateWindowEx function.
WM_GETTEXTLENGTH Process if the control text is not the same as the title specified by the CreateWindowEx function.
WM_KILLFOCUS Process if the control displays a caret, a focus rectangle, or another item to indicate that it has the input focus.
WM_SETFOCUS Process if the control displays a caret, a focus rectangle, or another item to indicate that it has the input focus.
WM_SETTEXT Process if the control text is not the same as the title specified by the CreateWindowEx function.
WM_SETFONT Process if the control displays text. Windows sends this message when creating a dialog box that has the DS_SETFONT style.

Application-defined control messages are specific to the given control and must be explicitly sent to the control by using a SendMessage or SendDlgItemMessage function. The numeric value for each message must be unique and must not conflict with the values of other window messages. To ensure that application-defined message values do not conflict, an application should create each value by adding a unique number to the WM_USER value.