读书人

if( nChar == L#039;C#039; amp;amp; GetKeyState(V

发布时间: 2012-03-17 19:06:28 作者: rapoo

if( nChar == L'C' && GetKeyState(VK_CONTROL) < 0 ) 没反应呢
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);   } 

读书人网 >VC/MFC

热点推荐