Code::使用HotKeyCtrl定义一个系统热键 |
// 关联HotKeyCtrl控件变量 m_HotKey1 BEGIN_MESSAGE_MAP(CXyzDlg, CDialog) //{{AFX_MSG_MAP(CXyzDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CXyzDlg::OnButton1() { // TODO: Add your control notification handler code here WORD m_wVkCode; WORD m_wModifier; m_HotKey1.GetHotKey(m_wVkCode, m_wModifier); AfxGetMainWnd()->SendMessage(WM_SETHOTKEY,(WPARAM)MAKEWORD(m_wVkCode,m_wModifier)); UINT mod = 0; if ( m_wModifier&HOTKEYF_ALT ) mod|=MOD_ALT; if ( m_wModifier&HOTKEYF_CONTROL ) mod|=MOD_CONTROL; if ( m_wModifier&HOTKEYF_SHIFT ) mod|=MOD_SHIFT; if ( m_wModifier&HOTKEYF_EXT ) mod|=MOD_WIN; m_wModifier=mod; ::RegisterHotKey(AfxGetMainWnd()->m_hWnd, 111 , m_wModifier, m_wVkCode); } void CXyzDlg::OnHotKey(WPARAM wParam, LPARAM lParam) { switch (wParam) case 111: AfxMessageBox("热键响应成功!"); // CDialog::OnHotKey(wParam,lParam); } void CXyzDlg::OnClose() { // TODO: Add your message handler code here and/or call default ::UnregisterHotKey(m_hWnd,111); CDialog::OnClose(); } 效果图: |
C++ Code_HotKey,布布扣,bubuko.com