|
-
May 21st, 1999, 05:32 AM
#1
capture ESC key in MFC
I have to prevent the default ESC key action in MFC in a dialog box (do the same as the Cancel button): the Cancel Button must works normally, but if the user press the ESC key, nothing does happened.
How can I do that ?
Thanks in advance, Pascal.
-
May 21st, 1999, 05:46 AM
#2
Re: capture ESC key in MFC
Override your dialog PreTranslateMessage() function like this:
int CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==27) return 0;
else return CDialog::PreTranslateMessage(pMsg);
}
-
May 21st, 1999, 07:39 AM
#3
Re: capture ESC key in MFC
With one small change ric's code becomes excellent:
I'd write it like this instead and it will be all honky-dory:
int CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
return 0;
return CDialog::PreTranslateMessage(pMsg);
}
-
May 21st, 1999, 08:40 AM
#4
Re: capture ESC key in MFC
Thanks to you, that's all good.
Just a little problem: when I do as you told me, the computer bips when I push on ESC. Why ? Is there a mean to avoid that ?
-
May 22nd, 1999, 06:44 AM
#5
Re: capture ESC key in MFC
Try this:
int CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
return 1; // nore the return value changed
return CDialog::PreTranslateMessage(pMsg);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|