首页 > 代码库 > C++ Code_HotKey
C++ Code_HotKey
Code::使用HotKeyCtrl定义一个系统热键 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> |
// 关联HotKeyCtrl控件变量 m_HotKey1 BEGIN_MESSAGE_MAP(CXyzDlg, CDialog) //{{AFX_MSG_MAP(CXyzDlg) ON_WM_SYSCOMMAND() ON_MESSAGE(WM_HOTKEY,OnHotKey) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 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(); } 效果图: |
来自为知笔记(Wiz)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。