MFC對話框里不響應按鍵事件的解決辦法


原因:MFC在進行設計的時候,這兩個消息被對話框上的控件截獲了,不能到達消息響應函數。
1,在窗口類的聲明時添加一個虛函數:virtual BOOL PreTranslateMessage(MSG* pMsg);
2,在.cpp 中實現。
BOOL CCustomJobSetDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (WM_KEYDOWN == pMsg->message) {
if(!(GetKeyState(VK_SHIFT) < 0)) {
switch(pMsg->wParam) {
case VK_PRIOR:
case VK_NEXT:
case VK_END:
case VK_HOME:
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
return 1;
}
}
}

return CDialog::PreTranslateMessage(pMsg);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM