Solved

Escape key

Posted on 1999-01-01
6
652 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
6 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 100 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now