Click to See Complete Forum and Search --> : Vc++
vikashkr23
February 22nd, 2003, 08:37 AM
hello Friend!!
plz help me. I dont want to close the Dialog in VC++ with ESC or Enter key press of Keyboard.Anywau is having then Plz helpme.Where to write the code.
Vikash
Andreas Masur
February 23rd, 2003, 03:17 AM
The default behaviour for the 'ENTER' and 'ESC' keys are 'IDOK' and 'IDCANCEL'. Both will close your dialog. To avoid this you can do the following things...
1. Overriding 'PreTranslateMessage()'
BOOL CYourDialog::PreTranslateMessage(MSG* pMsg)
{
// ENTER key
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
return TRUE;
// ESC key
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
2. Overriding 'OnOK()' or 'OnCancel()'
// ENTER key
void CYourDialog::OnOK()
{
// CDialog::OnOK(); <-- Disable this line
}
// ESC key
void CYourDialog::OnCancel()
{
// CDialog::OnCancel(); <-- Disable this line
}
These are of course only 2 ways...for additional information take a look at this FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231075)
satheeshnl
February 25th, 2003, 04:35 PM
Or change the default id values (IDOK, IDCANCEL) to something else, so that the default map is disabled.
-satheesh
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.