捕获组合键VC编程

① 捕获【Ctrl、Ctrl+Alt】和【Ctrl+Alt+Shift】这样的组合键:

BOOL CTestDlg::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;
		}
	}

②  捕获【 Ctrl + Z 】组合键:

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg) 
{
	char nChar = pMsg->wParam;
	if(nChar == 'Z' && ((GetAsyncKeyState( VK_LCONTROL ) & 0x8000)))
	{
		AfxMessageBox("ctrl + z");
	}
	return CDialog::PreTranslateMessage(pMsg);
}


你可能感兴趣的:(捕获组合键VC编程)