C++ Code_HotKey
Code::使用HotKeyCtrl定义一个系统热键
|
// 关联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();
}
效果图: |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。