首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

if( nChar == L'C' && GetKeyState(VK_CONTROL) < 0 ) 没反应呢,该怎么解决

2012-03-17 
if( nChar LC &&GetKeyState(VK_CONTROL) 0 )没反应呢nChar用67测试也没反应!!C/C++ codeBEGIN_MES

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);   } 

热点排行