【问题标题】:closing MFC application only using [X] button in title bar and disabling esc shortcut仅使用标题栏中的 [X] 按钮关闭 MFC 应用程序并禁用 esc 快捷方式
【发布时间】:2017-04-08 11:04:11
【问题描述】:

我有一个基于对话框的 MFC 应用程序,我只想使用标题栏中给出的 X(关闭)按钮并禁用其他快捷方式来关闭/终止它。
例如:按 Esc 键。有人可以帮忙吗?

【问题讨论】:

标签: c++ mfc modal-dialog terminate


【解决方案1】:

重写 PreTranslateMessage 函数并捕获使用 VK_ESCAPE 来捕获 Esc 键。类似的方式,您可以捕获其他消息并绕过关闭对话框

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

【讨论】:

  • 复制poor answer,不注明出处,称为“抄袭”。 -1 甚至没有考虑正确的 MFC 方式。
  • 请让我知道我在这里以非 MFC 方式在做什么,因为我在以前的项目中使用过它并复制了它。让我知道什么是非 MFC 方式,这样我也可以在我的项目中做到这一点。非常感谢您的回答。
猜你喜欢
  • 2019-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-21
  • 2016-11-21
  • 2018-02-22
  • 1970-01-01
  • 2013-07-31
相关资源
最近更新 更多