?
Solved

Escape key

Posted on 1999-01-01
6
Medium Priority
?
717 Views
Last Modified: 2013-11-20
Also, in my program, the {Esc} key will exit it.  I do not want this to happen.  I want the escape key to do nothing.  What can I do to disable this stupid escape key?
0
Comment
Question by:abc021397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 400 total points
ID: 1327115
To solve this problem, you want to override the OnCancel member function.  Here is what you want to do:
1) Open up your dialog header file, named something like CMyDlg.h
2) Add:
   void OnCancel ();
   somewhere in the "public:" area.
3) Open up your dialog source code file, named something like CMyDlg.cpp
4) Add:
   void CMyDlg::OnCancel ()
   {
   }
   to the end of the file.
5) Recompile
6) Run and voila! No more escape key exiting.

If you have any further questions on how to implement this or are having any other difficulty, please feel free to ask.  Thanks!
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1327116
thresh,
Now suppose there is the Cancel command button with the ID value of IDCANCEL. OnCancel will be mapped to the clicked event of this button. Now overriding the OnCancel will not only disable the Escape key but will also prevent the user from exiting if the Cancel button is clicked. How about only disabling the escape key?

0
 
LVL 1

Expert Comment

by:dd_b
ID: 1327117
overridding OnCancel may create a problem while exiting on Cancel Button.

The Best way is in OnKeyDown

afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
{
//compare

if ( nChar == VK_ESCAPE )
   return;
else

BaseClass::OnKeyDown

}

0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327118
Thank you dd_b for providing the code.  Here it was night time which is why I did not respond sooner.

abc - If you can use either method to cancel the esc key's effect.  As has been shown, the second method is better.
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1327119
NOO not OnKeyDown

PreTranslateMessage(MSG pMsg)
{
   if (GetAsyncKeyState(VK_ESCAPE))
     {
        do what you wan't to do to kill the button;
        I would probably say
        VK_ESCAPE=0;
     }
     
}

Don't use OnKeyDown.  It sometimes for some odd reason doesn't capture keys.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1327120
The_Brain, you're right. There are times when OnKeyDown will not work. I think PreTranslateMessage will work.
However as suggested by you VK_ESCAPE=0 will not work. VK_ESCAPE is already a predefined constant. You cannot change its value.


0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

770 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