Click here to Skip to main content
Licence 
First Posted 12 Jan 2000
Views 62,187
Bookmarked 35 times

Catching the 'Enter' Key in windows and controls

By | 12 Jan 2000 | Article
How to handle the WM_GETDLGCODE message in order to catch special key strokes.

In order to catch the "Enter" key, and other special keys in a CListCtrl (or any control for that matter) it is necessary to derive your own class and add a handler for the WM_GETDLGCODE message. To allow all special keys to be processed by the control add the following:

UINT SMUPPGrid::OnGetDlgCode()
{ 
	UINT result = CListCtrl::OnGetDlgCode();
	result = result | DLGC_WANTALLKEYS;
	return result;
}

Other options include (from MSDEV documentation):

  • DLGC_WANTALLKEYS: All keyboard input.
  • DLGC_WANTARROWS: Arrow keys.
  • DLGC_WANTCHARS: WM_CHAR messages.
  • DLGC_WANTMESSAGE: All keyboard input. The application passes this message on to the control.
  • DLGC_WANTTAB: TAB key.
  • DLGC_BUTTON: Button (generic).
  • DLGC_DEFPUSHBUTTON: Default pushbutton.
  • DLGC_HASSETSEL: EM_SETSEL messages.
  • DLGC_UNDEFPUSHBUTTON: No default pushbutton processing. (An application can use this flag with DLGC_BUTTON to indicate that it processes button input but relies on the system for default pushbutton processing.)
  • DLGC_RADIOBUTTON: Radio button.
  • DLGC_STATIC: Static control.

This is a relatively simple process but it is not really all that intuitive or well documented.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Randy More



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 Pinmemberbuyong17:18 25 Sep '11  
QuestionIs this kind of catching ENTER Key wrong ? PinmemberfG4:59 20 Jan '01  
Using Class Wizard insert PreTranslateMessage
 
// TODO: Add your specialized code here
 
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN)
{
MessageBox("Pressed ENTER","Title",MB_OK|MB_ICONINFORMATION);
return 0;
}
AnswerRe: Is this kind of catching ENTER Key wrong ? PinmemberArsi Rantala23:31 25 Feb '01  
AnswerRe: Is this kind of catching ENTER Key wrong ? PinmemberGeorge Archibald10:45 13 Aug '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 13 Jan 2000
Article Copyright 2000 by Randy More
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid