如何捕获Ctrl、Ctrl+Alt和Ctrl+Alt+Shift组合键

如何捕获Ctrl、Ctrl+Alt和Ctrl+Alt+Shift组合键
 BOOL CTestView::PreTranslateMessage(MSG* pMsg)
 {
  if(pMsg->message==WM_KEYDOWN)
  {
   BOOL bCtrl=::GetKeyState(VK_CONTROL)&0x8000;
   BOOL bShift=::GetKeyState(VK_SHIFT)&0x8000;
   BOOL bAlt=::GetKeyState(VK_MENU)&0x8000;
   switch(pMsg->wParam)
   {
   case VK_DELETE:
    if(bCtrl&&bAlt&&bShift)
     MessageBox("你按下的是Ctrl+Shift+Alt+Delete组合键",
                                                   "信息提示",MB_OK);
    else if(bCtrl&&bShift)
     MessageBox("你按下的是Ctrl+Shift+Delete组合键",
                                                   "信息提示",MB_OK);
    else if(bCtrl)
     MessageBox("你按下的是Ctrl+Delete组合键",
                                                   "信息提示",MB_OK);
    return TRUE;
   case VK_INSERT:
    if(bCtrl&&bAlt&&bShift)
     MessageBox("你按下的是Ctrl+Shift+Alt+Insert组合键",
                                                   "信息提示",MB_OK);
    else if(bCtrl&&bAlt)
     MessageBox("你按下的是Ctrl+Alt+Insert组合键",
                                                   "信息提示",MB_OK);
    else if(bCtrl)
     MessageBox("你按下的是Ctrl+Insert组合键",
                                                   "信息提示",MB_OK);
    return TRUE;
   }
  }
  return CView::PreTranslateMessage(pMsg);
 }

你可能感兴趣的:(组合键)