if( nChar == L'C' && GetKeyState(VK_CONTROL) < 0 ) 没反应呢,该怎么解决
if( nChar == L'C' && GetKeyState(VK_CONTROL) < 0 ) 没反应呢
nChar用67测试也没反应!!
------解决方案--------------------
要在PretranslateMessage里面才行。
------解决方案--------------------
nChar
Contains the character code value of the key.
------解决方案--------------------
Ctrl Shift之类的控制键无法在OnChar中获取到,因为不是字符。
如jennyvenus所说用PretranslateMessage截获消息:
sample code here :
nChar用67测试也没反应!!
- C/C++ code
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd) ON_WM_CHAR() END_MESSAGE_MAP() void CMainWindow::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags ) { if( nChar == L'C' && GetKeyState(VK_CONTROL) < 0 ) MessageBox(L"复制"); }
------解决方案--------------------
要在PretranslateMessage里面才行。
------解决方案--------------------
nChar
Contains the character code value of the key.
------解决方案--------------------
Ctrl Shift之类的控制键无法在OnChar中获取到,因为不是字符。
如jennyvenus所说用PretranslateMessage截获消息:
sample code here :
- C/C++ code
BOOL CXXEdit::PreTranslateMessage(MSG* pMsg) { if(WM_KEYDOWN == pMsg->message) { if(::GetFocus() == m_hWnd && (GetKeyState( VK_CONTROL) & 0xFF00 ) == 0xFF00) { // 全选 if( pMsg->wParam == 'A' || pMsg->wParam == 'a') { this->SetSel(0, -1); return true; } // 拷贝 if( pMsg->wParam == 'C' || pMsg->wParam == 'c') { this->Copy(); return true; } // 剪切 if( pMsg->wParam == 'X' || pMsg->wParam == 'x') { this->Cut(); return true; } // 粘贴 if( pMsg->wParam == 'V' || pMsg->wParam == 'v') { this->Paste(); return true; } // 粘贴 if( pMsg->wParam == 'Z' || pMsg->wParam == 'z') { this->Undo(); return true; } } } return CEdit::PreTranslateMessage(pMsg); }