利用RegisterHotKey注册多个热键。自己定义系统的WM_HOTKEY消息
hotKeyDlg.h
afx_msg LONG OnHotKey(WPARAM wPARAM, LPARAM lPARAM);
hotKeyDlg.cpp
#define ID_EXIT 0x5000
#define ID_SHOW 0X6000
BEGIN_MESSAGE_MAP(CHotKeyDlg, CDialog)
//{{AFX_MSG_MAP(CHotKeyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_HOTKEY, OnHotKey)
BOOL CHotKeyDlg::OnInitDialog()
{
...
::RegisterHotKey(m_hWnd, ID_EXIT, MOD_ALT, '5');
::RegisterHotKey(m_hWnd, ID_SHOW, MOD_ALT, '6');
}
LONG CHotKeyDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if (wParam == ID_EXIT)
{
PostMessage(WM_QUIT, NULL, NULL);
}
if(wParam == ID_SHOW)
{
AfxMessageBox("ALT + 6", 0, 0);
}
return 0;
}
void CHotKeyDlg::OnDestroy()
{
CDialog::OnDestroy();
UnregisterHotKey(m_hWnd, ID_EXIT);
UnregisterHotKey(m_hWnd, ID_SHOW);
}
posted on 2010-03-18 11:49
漂漂 阅读(6071)
评论(0) 编辑 收藏 引用 所属分类:
深入vc++