项目中开发的一个多文档程序中用到了快键键F10,发现当按F10快键键时,软件焦点会跳到菜单栏上面,网上查到许多的资料都讲的不太准确,下面介绍一种最简单的屏蔽方法,不需要去注册注销热键消息,
1、在CMainFrm添加虚函数PreTranslateMessage。
2、在虚函数中添加对系统热键VK_F10的消息进行屏蔽。
代码如下:
virtual BOOL PreTranslateMessage(MSG* pMsg);
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if( VK_F10 == pMsg->wParam &&WM_SYSKEYUP == pMsg->message) //F10为系统热键,按下时会响应系统消息,在此单独处理
{
return TRUE;
}
return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}
注意:
1、pMsg->message为判断系统按键是否松开;
2、消息返回为TRUE时系统对该消息的处理结束,返回FALSE时会继续对该消息进行下一步处理。