[英]Override OnCancel button in MFC/Visual C++
I have a model dialog. 我有一个模型对话框。 I overrided OnCancel function to stop unexpected exiting by pressing ESC button.
我重写了OnCancel函数,以通过按ESC按钮停止意外退出。 But this caused a new problem.
但这引起了新的问题。 I can't close the application by using close (x) button.
我无法使用关闭(x)按钮关闭该应用程序。 My implementation of function is:
我的功能实现是:
void MyDlg::OnCancel()
{
}
Closing a dialog effectively cancels it. 关闭对话框可以将其取消。 Since you have disabled close in your OnCancel handler, then nothing will happen.
由于您已在OnCancel处理程序中禁用关闭,因此将不会发生任何事情。
To disable ESC only, you need to preprocess the keyboard messages: 要仅禁用ESC,您需要预处理键盘消息:
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
switch ( pMsg->message )
{
case WM_KEYDOWN:
switch( pMsg->wParam )
{
case VK_ESCAPE:
case VK_CANCEL: return true;
}
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.