MFC - CDialog - Escape Key - Solved - OnCancel()

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Have an program written/created using the MFC wizard dialog app template

Problem is that the F1 key is too close to the Escape key.
Users may hit the Escape key and kill the app.

I can not seem to trap the Escape Key Keydown message.
Does not show as SYSCHAR, SYSCOMMAND, KEYDOWN or Close message.
First time I can detect it is at the DestroyWindow - then it is to late.

Guidance will be greatly appreciated.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: EagleKeeper
Got it - Overriding the OnCancel handler
Always a good idea for any dialogs that the user must answer, since even if you delete [Cancel] the [x] and escape key still send IDCANCEL which has a default handler in CDialog.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
FYI, there is a virtual function OnOK() that is the default handler for the ENTER key :)