The information in this article applies to:
SUMMARY
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.
MORE INFORMATIONWindows sends a WM_GETDLGCODE message to a control for the following three reasons:
The window procedure for each predefined control returns an
appropriate value in response to a WM_GETDLGCODE message. The value is
one or more of the following codes, combined with the Boolean OR
operator:
The return codes above can be used by user-defined controls or, in a
subclass procedure, to modify the behavior of predefined controls. To
subclass a control, call the predefined control's window procedure
first, then modify the necessary bits in the return code.
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:
When a check box control's subclass procedure includes the code above,
Windows performs no further processing for WM_CHAR messages for the X,
x, O, and o characters because the value returned from WM_GETDLGCODE
includes the DLGC_WANTMESSAGE code. In the example above, the control
could have returned DLGC_WANTCHARS instead of DLGC_WANTMESSAGE because
the WM_CHAR message is the only message processed by the control.
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.Additional query words:
Keywords : kbDlg kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS310 kbWndw kbWndwMsg kbWinOS300 |
Last Reviewed: January 27, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |