Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How inhibe the ENTER and ESC KEYS ?

Status
Not open for further replies.

youssef

Programmer
Mar 13, 2001
96
BE
Hi,
I created a project. I deleted the OK and CANCEL buttons. But when I execute my project and I press the ESC or ENTER KEYS, the project is stopped.

How can I do for inhibe this KEYS?

Best Regards
 
Yes, windows still inteprete ESC key as the OnCancel message handler, because OnCancel is in CDialog class, it still can be invoked even if you delete the Cancel button.

The solution is : override the PreTranslateMessage function
and modify it:

BOOL CTestDlgDlg::preTranslateMessage(MSG* pMsg)
{

if (pMsg->message == WM_KEYDOWN){
if( pMsg->wParam == VK_ESCAPE) return true;
}
return CDialog::preTranslateMessage(pMsg);
}

This will ingore the ESC key.

I don't think return key will close your dialog after you delete the OK button from it. If it does happen, pls let's know.
 
Thank you very much.
The ESC key is inhibe and RETURN KEY is inhibed when I delete the OK button.

Best Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top