当按下ESC键时,关闭应用程序

来源:互联网 发布:mysql wait timeout 编辑:程序博客网 时间:2024/06/05 04:35

在一个单文档MFC应用程序中,按下ESC时关闭应用程序,实现方法:在CMainFrame类里重载PreTranslateMessage(),代码如下:

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
 if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
 {
  PostQuitMessage(WM_QUIT);
 }
 
 return CFrameWnd::PreTranslateMessage(pMsg);
}

 

到此完成了。

 

如果只是关闭本窗口,可以使用:this->CloseWindow();,但应用程序不会退出!

原创粉丝点击