顯示具有 MFC 標籤的文章。 顯示所有文章
顯示具有 MFC 標籤的文章。 顯示所有文章

2018年1月26日 星期五

[程式] How to avoid to close MFC application by pressing ECS and Enter

By default, press ECS and Enter will close MFC application. Here is the solution to prevent this behavior.

Project -> Class Wizard -> Choose correct Project and Class name -> Choose 'Virtual Functions' sheet -> PreTranslateMessage -> Add Function

Implement function as below.

BOOL CSystemInfoDlg::PreTranslateMessage(MSG* pMsg) {
    if (pMsg->message == WM_KEYDOWN) {
        if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) {
            return TRUE;
        }
    }
    return CDialogEx::PreTranslateMessage(pMsg);
}