|
-
May 24th, 1999, 04:31 PM
#1
Trapping ESC in Dialog Boxes
Hello all,
Does anyone know how to trap the ESC key in a dialog box so that it does not close the dialog?
I would appreciate any leads at all! Please email [email protected]
Jeremy
-
May 24th, 1999, 05:02 PM
#2
Re: Trapping ESC in Dialog Boxes
Override OnCancel(), don't call CDialog::OnCancel() in that function.
-
May 24th, 1999, 10:01 PM
#3
Re: Trapping ESC in Dialog Boxes
CMyDialog::OnCancel()
{
return;
//CDialog::OnCancel();
}
if u don't want to close Dialog with Enter key, it is same.
CMyDialog::OnOK()
{
return;
//CDialog::OnOK();
}
-
May 25th, 1999, 12:12 AM
#4
Re: Trapping ESC in Dialog Boxes
Actually doing this will prevent the Cancel button from working at all!!! What you need to do is to overload PreTranslateMessage and impliment it like this...
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
if (pMsg->wParam == VK_ESCAPE)
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
This will give you the desired effect without completely disabling the cancel button.
-
May 25th, 1999, 11:54 AM
#5
Re: Trapping ESC in Dialog Boxes
Why not write it like the following for enhanced efficiency and better readability?
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
- Troy
-
May 26th, 1999, 12:33 AM
#6
Re: Trapping ESC in Dialog Boxes
How does that make it more readable??? I think it is more confusing to have multiple && statments in an if statement. Not oly that but my method allows you to check for other keys by simply adding another if statment. For example
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN){
if (pMsg->wParam == VK_ESCAPE)
return TRUE;
if (pMsg->wParam == VK_RETURN)
// Do something for the enter key
}
return CDialog::PreTranslateMessage(pMsg);
}
would also trap the enter key and allow you to process them seperatly.
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
|