Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Override Enter/Esc keys in the CDialog

Posted on 2003-02-21
5
Medium Priority
?
825 Views
Last Modified: 2013-11-20
I need to override the behaviour of my CDialog-derived class when Enter or Esc key is pressed, but this event is not caught in CDialog::OnKeyDown(), and, although these keys generally hide the dialog, CWnd::OnWindowShow() is never called either. What message handler should I look for?
0
Comment
Question by:milchenko
5 Comments
 

Expert Comment

by:nik2k
ID: 7995985
You have to override OnOK and OnCancel
0
 
LVL 1

Expert Comment

by:jackrabbit22
ID: 7996450
0
 

Expert Comment

by:vjayaprasen
ID: 7997660
u can override OnOk() for Enter & OnCancel()for Esc.This look like
   void CMyDialog::OnOK()
   {
   }
   void CMyDialog::OnCancel()
   {
   }
this can be done by simply add a two methods in class wizard as in the above
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 400 total points
ID: 7997896
Or you can look at PreTranslateMessage():

BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
  if (pMsg->message == WM_KEYDOWN && 
      (pMsg->wParam == VK_ESC || pMsg->Param == VK_ENTER)
    return TRUE;

  return CDialog::PreTranslateMessage(pMsg); // Or parent class if not CDialog
}

Good Luck,
Steve
0
 

Author Comment

by:milchenko
ID: 8001644
Thanks, this looks like the best code that would work for all cases.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question