You are currently offline, waiting for your internet to reconnect

How To Use the WM_GETDLGCODE Message

This article was previously published under Q83302
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
Windows sends a WM_GETDLGCODE message to controls in a dialog box orin a window where the IsDialogMessage function handles keyboard input.Generally, an application processes the WM_GETDLGCODE message toprevent Windows from performing default processing in response tokeyboard messages. The WM_KEYDOWN, WM_SYSCHAR, and WM_CHAR messagesare examples of keyboard messages.

This article discusses the various codes that make up the valuereturned from the WM_GETDLGCODE message.
MORE INFORMATION
Windows sends a WM_GETDLGCODE message to a control for the followingthree reasons:
  • To determine whether the control will process a particular type of input.
  • To determine whether the text contents of an edit control are selected when, as a result of the user pressing the TAB key, the edit control receives the input focus.
  • To determine the type of a button.
The following text documents the values of the wParam and lParamparameters for the WM_GETDLGCODE message:
   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.				
The window procedure for each predefined control returns anappropriate value in response to a WM_GETDLGCODE message. The value isone or more of the following codes, combined with the Boolean ORoperator:
   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.				
The return codes above can be used by user-defined controls or, in asubclass procedure, to modify the behavior of predefined controls. Tosubclass a control, call the predefined control's window procedurefirst, then modify the necessary bits in the return code.

DLGC_WANTALLKEYS, DLGC_WANTARROWS,DLGC_WANTCHARS, DLGC_WANTMESSAGE, and DLGC_WANTTAB Return Codes

When a control processes the WM_GETDLGCODE message and the value itreturns has one of the DLGC_WANT* bits set, the control will processthe specified message type and Windows will not do any defaultprocessing for messages of the specified type.

For example, the code returned by a list box includes DLGC_WANTARROWSto indicate that the list box processes arrow keys. When a list boxhas the focus and the user presses a DOWN ARROW key, Windows sends aWM_GETDLGCODE message to the list box. Because the return valueincludes the DLGC_WANTARROWS code, Windows allows the list box toprocess the arrow keystroke and performs no further processing. If thereturn value did not include the DLGC_WANTARROWS code, Windows wouldcontinue processing the arrow keystroke and would change the focus tothe next control in the current control group.

As another example, the value returned by an edit control includes theDLGC_WANTCHARS code while the value returned by a button does not.Consequently, if a button has the focus, and the user types a validmnemonic character, Windows sets the focus to the control in thedialog box that corresponds to the mnemonic. (If a control has amnemonic character, it is underlined in the control's label.) If anedit control has the focus and the user types a mnemonic character,however, Windows does not change the input focus because the editcontrol processes the resulting WM_CHAR message and Windows does notperform its default processing for a mnemonic character.

DLGC_WANTMESSAGE Code

A control returns a value that includes the DLGC_WANTMESSAGE codeafter it processes the message sent through the lParam thataccompanies the WM_GETDLGCODE message. The DLGC_WANTMESSAGE codeindicates that the application does not want default processing forthe message to continue. The messages sent to the control includeWM_KEYDOWN, WM_SYSCHAR, and WM_CHAR. Future versions of Windows couldsend other messages to controls using this mechanism.

The following code provides an example of processing the WM_GETDLGCODEmessage in a control's subclass procedure. In the example, the userpresses the "X" key to select a check box and presses the "O" key toclear the check bobox:
   case WM_GETDLGCODE:      // Call the check box window procedure first      lRet = CallWindowProc(lpCheckProc, hWnd, wMessage, wParam,                            lParam);      // If lParam points to an MSG structure      if (lParam)      {         lpmsg = (LPMSG)lParam;         if (lpmsg->message == WM_CHAR)         {            if (lpmsg->wParam == 'x' || lpmsg->wParam == 'X')            {               // Select the check box when user presses "X"               SendMessage(hWnd, BM_SETCHECK, TRUE, 0);               lRet |= DLGC_WANTMESSAGE;            }            else if (lpmsg->wParam == 'o' || lpmsg->wParam == 'O')            {               // Clear the check box when user presses "O"               SendMessage(hWnd, BM_SETCHECK, FALSE, 0);               lRet |= DLGC_WANTMESSAGE;            }         }      }      return lRet;				
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_GETDLGCODEincludes the DLGC_WANTMESSAGE code. In the example above, the controlcould have returned DLGC_WANTCHARS instead of DLGC_WANTMESSAGE becausethe WM_CHAR message is the only message processed by the control.

DLGC_HASSETSEL Code

An edit control returns a value that includes the DLGC_HASSETSEL codeto indicate that Windows should select all the text in an edit controlwhen the control receives the input focus through the tabbingsequence.

For example, when a control in a dialog box receives the focus becausethe user pressed the TAB key, Windows sends a WM_GETDLGCODE message tothe control. If the value returned from the edit control includes theDLGC_HASSETSEL code, the edit control indicates that all text in theedit control should be selected. Consequently, Windows sends anEM_SETSEL message to the control to select all its contents.

An application can alter this behavior and prevent the contents frombeing selected when the control receives the focus through tabbing, bysubclassing the edit control and removing the DLGC_HASSETSEL code fromits return value. Note that the subclassing code below does not changeany other bits in the return value.
     // In the subclass procedure   case WM_GETDLGCODE:      // Call the original edit control window procedure      lRet = CallWindowProc(lpEditProc, hWnd, wMessage, wParam,                            lParam);      // Clear the DLGC_HASSETSEL bit from the return value      lRet &= ~DLGC_HASSETSEL;      return lRet;				

DLGC_BUTTON, DLGC_DEFPUSHBUTTON,DLGC_UNDEFPUSHBUTTON, DLGC_RADIOBUTTON, DLGC_STATIC Codes

These codes are used to determine a control's attributes.
Properties

Article ID: 83302 - Last Review: 08/30/2004 22:05:17 - Revision: 3.2

Microsoft Windows Software Development Kit 3.0, Microsoft Windows Software Development Kit 3.1

  • kbdlg kbhowto kbwndw KB83302
Feedback
var varAutoFirePV = 1; var varClickTracking = 1; var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" geScreens track by $index" class="col-sm-6 col-xs-24 ng-scope"> Paraguay - Español
Venezuela - Español
://c1.microsoft.com/c.gif?DI=4050&did=1&t=">var varClickTracking = 1; var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" ad="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?"> >>