Article ID: 83302 - Last Review: August 30, 2004 - Revision: 3.2 How To Use the WM_GETDLGCODE MessageThis article was previously published under Q83302 On This PageSUMMARY
Windows sends a WM_GETDLGCODE message to controls in a dialog box or
in a window where the IsDialogMessage function handles keyboard input.
Generally, an application processes the WM_GETDLGCODE message to
prevent Windows from performing default processing in response to
keyboard messages. The WM_KEYDOWN, WM_SYSCHAR, and WM_CHAR messages
are examples of keyboard messages.
This article discusses the various codes that make up the value returned from the WM_GETDLGCODE message. MORE INFORMATION
Windows sends a WM_GETDLGCODE message to a control for the following
three reasons:
Parameter Description
------------------------------------------------------------------------
wParam Not used.
lParam If lParam is not NULL, it is a far pointer to an MSG
structure that contains a message that is being sent to
the control. Windows versions 3.0 and 3.1 use lParam only
to send keyboard input to the control. Keyboard messages
include WM_KEYDOWN, WM_SYSCHAR, and WM_CHAR. Future
versions of Windows may use lParam to send other message
types to controls.
Code Meaning
------------------------------------------------------------------------
DLGC_BUTTON Control is a button (of any kind).
DLGC_DEFPUSHBUTTON Control is a default push button.
DLGC_HASSETSEL Windows will send an EM_SETSEL message to the
control to select its contents.
DLGC_RADIOBUTTON Control is an option (radio) button.
DLGC_STATIC Control is a static control.
DLGC_UNDEFPUSHBUTTON Control is a push button but not the default
push button.
DLGC_WANTALLKEYS Control processes all keyboard input.
DLGC_WANTARROWS Control processes arrow keys.
DLGC_WANTCHARS Control processes WM_CHAR messages.
DLGC_WANTMESSAGE Control processes the message in the MSG
structure that lParam points to.
DLGC_WANTTAB Control processes the TAB key.
DLGC_WANTALLKEYS, DLGC_WANTARROWS, DLGC_WANTCHARS, DLGC_WANTMESSAGE, and DLGC_WANTTAB Return CodesWhen a control processes the WM_GETDLGCODE message and the value it returns has one of the DLGC_WANT* bits set, the control will process the specified message type and Windows will not do any default processing for messages of the specified type.For example, the code returned by a list box includes DLGC_WANTARROWS to indicate that the list box processes arrow keys. When a list box has the focus and the user presses a DOWN ARROW key, Windows sends a WM_GETDLGCODE message to the list box. Because the return value includes the DLGC_WANTARROWS code, Windows allows the list box to process the arrow keystroke and performs no further processing. If the return value did not include the DLGC_WANTARROWS code, Windows would continue processing the arrow keystroke and would change the focus to the next control in the current control group. As another example, the value returned by an edit control includes the DLGC_WANTCHARS code while the value returned by a button does not. Consequently, if a button has the focus, and the user types a valid mnemonic character, Windows sets the focus to the control in the dialog box that corresponds to the mnemonic. (If a control has a mnemonic character, it is underlined in the control's label.) If an edit control has the focus and the user types a mnemonic character, however, Windows does not change the input focus because the edit control processes the resulting WM_CHAR message and Windows does not perform its default processing for a mnemonic character. DLGC_WANTMESSAGE CodeA control returns a value that includes the DLGC_WANTMESSAGE code after it processes the message sent through the lParam that accompanies the WM_GETDLGCODE message. The DLGC_WANTMESSAGE code indicates that the application does not want default processing for the message to continue. The messages sent to the control include WM_KEYDOWN, WM_SYSCHAR, and WM_CHAR. Future versions of Windows could send other messages to controls using this mechanism.The following code provides an example of processing the WM_GETDLGCODE message in a control's subclass procedure. In the example, the user presses the "X" key to select a check box and presses the "O" key to clear the check bobox: DLGC_HASSETSEL CodeAn edit control returns a value that includes the DLGC_HASSETSEL code to indicate that Windows should select all the text in an edit control when the control receives the input focus through the tabbing sequence.For example, when a control in a dialog box receives the focus because the user pressed the TAB key, Windows sends a WM_GETDLGCODE message to the control. If the value returned from the edit control includes the DLGC_HASSETSEL code, the edit control indicates that all text in the edit control should be selected. Consequently, Windows sends an EM_SETSEL message to the control to select all its contents. An application can alter this behavior and prevent the contents from being selected when the control receives the focus through tabbing, by subclassing the edit control and removing the DLGC_HASSETSEL code from its return value. Note that the subclassing code below does not change any other bits in the return value. DLGC_BUTTON, DLGC_DEFPUSHBUTTON, DLGC_UNDEFPUSHBUTTON, DLGC_RADIOBUTTON, DLGC_STATIC CodesThese codes are used to determine a control's attributes.APPLIES TO
| Article Translations
|


Back to the top
