Trouble while trying to exit a dialog MFC App
-
I have a small dialog-type MFC App In order to not exit the app if I press ESC or Enter I wrote this: void CVariantDlg::OnOK(){} void CVariantDlg::OnCancel(){} In other words I overloaded the functions OnOK() and OnCancel(). It worked! Now I can press ESC or Enter and the app won't close. My problem is that even if I hit ALT-F4 or right-click it on the taskbar and choose close or hit the x button in the right side of the title bar it won't close! This sucks. I guess I should check to see what are the latest keys pressed and choose from that point on. BTW: How did you call the original function from the overloaded version of it? Anyways... what do you recommend me in order to have the application exit on: a) X button from title bar b) ALT-F4 c) Close from the system menu / taskbar rightclick and "Close" But not: a) ESC b) ENter ? TIA! ;-)
-
I have a small dialog-type MFC App In order to not exit the app if I press ESC or Enter I wrote this: void CVariantDlg::OnOK(){} void CVariantDlg::OnCancel(){} In other words I overloaded the functions OnOK() and OnCancel(). It worked! Now I can press ESC or Enter and the app won't close. My problem is that even if I hit ALT-F4 or right-click it on the taskbar and choose close or hit the x button in the right side of the title bar it won't close! This sucks. I guess I should check to see what are the latest keys pressed and choose from that point on. BTW: How did you call the original function from the overloaded version of it? Anyways... what do you recommend me in order to have the application exit on: a) X button from title bar b) ALT-F4 c) Close from the system menu / taskbar rightclick and "Close" But not: a) ESC b) ENter ? TIA! ;-)
Let the user use ESC or Enter, after all that is what most user will expect. Otherwise you could probably use GetKeyState() to determine which key was pressed, so you can decide when to allow box to close. INTP
-
I have a small dialog-type MFC App In order to not exit the app if I press ESC or Enter I wrote this: void CVariantDlg::OnOK(){} void CVariantDlg::OnCancel(){} In other words I overloaded the functions OnOK() and OnCancel(). It worked! Now I can press ESC or Enter and the app won't close. My problem is that even if I hit ALT-F4 or right-click it on the taskbar and choose close or hit the x button in the right side of the title bar it won't close! This sucks. I guess I should check to see what are the latest keys pressed and choose from that point on. BTW: How did you call the original function from the overloaded version of it? Anyways... what do you recommend me in order to have the application exit on: a) X button from title bar b) ALT-F4 c) Close from the system menu / taskbar rightclick and "Close" But not: a) ESC b) ENter ? TIA! ;-)
-
I have a small dialog-type MFC App In order to not exit the app if I press ESC or Enter I wrote this: void CVariantDlg::OnOK(){} void CVariantDlg::OnCancel(){} In other words I overloaded the functions OnOK() and OnCancel(). It worked! Now I can press ESC or Enter and the app won't close. My problem is that even if I hit ALT-F4 or right-click it on the taskbar and choose close or hit the x button in the right side of the title bar it won't close! This sucks. I guess I should check to see what are the latest keys pressed and choose from that point on. BTW: How did you call the original function from the overloaded version of it? Anyways... what do you recommend me in order to have the application exit on: a) X button from title bar b) ALT-F4 c) Close from the system menu / taskbar rightclick and "Close" But not: a) ESC b) ENter ? TIA! ;-)
Override a
PreTranslateMessage
:BOOL CVariantDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
WORD wKeyCode = LOWORD(pMsg->wParam);
if ((wKeyCode == 13) || (wKeyCode == VK_ESCAPE))
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}Robert-Antonio
-
Let the user use ESC or Enter, after all that is what most user will expect. Otherwise you could probably use GetKeyState() to determine which key was pressed, so you can decide when to allow box to close. INTP