Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Escape key

Posted on 1999-01-01
6
Medium Priority
?
726 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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