mfc 中的多个按键处理
Multiple Key Press handling in mfc
如何在MFC中处理多个按键。我尝试了几个键 combinations.But 如何概括所有键组合。
BOOL Test::PreTranslateMessage(MSG* pMsg){
if(pMsg->message==WM_KEYDOWN )
{
if(pMsg->wParam == 'C' || pMsg->wParam == 'V')
{
if(GetKeyState(VK_CONTROL) < 0){
}
}
}
}
您可以 GetKeyState 并检查按下了哪些键。
if ((::GetKeyState(_T('C')) & 0x8000)!=0 &&
(::GetKeyState(_T('V')) & 0x8000)!=0)
// C and V are down...
只要 WM_KEYDOWN 到达您的 PreTranslateMessage 函数,您就可以执行此检查。将此用于加速等普通键将起作用。 MFC 还在 PreTranslateMessage 函数中检查加速器。
您应该始终使用 GetKeyState,因为当您从消息队列收到的当前消息得到处理时,此函数会检查 down/up 哪些键。
正确的处理方式是WM_CUT, WM_COPY and WM_PASTE,因为copy/paste操作不仅可以Ctrl+C,还可以CTrl+Insert,等等...如果你想处理这些东西...
"PreTranslateMessage is dangerous territory": 真的!保重!
如何在MFC中处理多个按键。我尝试了几个键 combinations.But 如何概括所有键组合。
BOOL Test::PreTranslateMessage(MSG* pMsg){
if(pMsg->message==WM_KEYDOWN )
{
if(pMsg->wParam == 'C' || pMsg->wParam == 'V')
{
if(GetKeyState(VK_CONTROL) < 0){
}
}
}
}
您可以 GetKeyState 并检查按下了哪些键。
if ((::GetKeyState(_T('C')) & 0x8000)!=0 &&
(::GetKeyState(_T('V')) & 0x8000)!=0)
// C and V are down...
只要 WM_KEYDOWN 到达您的 PreTranslateMessage 函数,您就可以执行此检查。将此用于加速等普通键将起作用。 MFC 还在 PreTranslateMessage 函数中检查加速器。
您应该始终使用 GetKeyState,因为当您从消息队列收到的当前消息得到处理时,此函数会检查 down/up 哪些键。
正确的处理方式是WM_CUT, WM_COPY and WM_PASTE,因为copy/paste操作不仅可以Ctrl+C,还可以CTrl+Insert,等等...如果你想处理这些东西...
"PreTranslateMessage is dangerous territory": 真的!保重!