一、添加函数,屏蔽ENTER键和ESC键的使用:
BOOL CBingLi::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message ==WM_KEYDOWN)
{
int nVirtKey = (int)pMsg->wParam;
if (nVirtKey==VK_ESCAPE || nVirtKey == VK_RETURN)
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
二、添加函数,屏蔽组合键ALT+F4的使用:
BOOL CBingLi::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message ==WM_KEYDOWN)
{
int nVirtKey = (int)pMsg->wParam;
if(pMsg->message==WM_HOTKEY&&pMsg->wParam==0XA002 //屏蔽ALT+F4
{
return TRUE; //什么都不做
}
}
return CDialog::PreTranslateMessage(pMsg);
}
本文介绍如何通过添加函数来禁用特定的键盘输入,包括常见的ENTER键、ESC键以及组合键ALT+F4,在对话框中实现这些功能的具体代码示例。
6820

被折叠的 条评论
为什么被折叠?



