(1)注册热键
1
|
BOOL
re = RegisterHotKey(
this
->m_hWnd, 0x2901, MOD_CONTROL,
'A'
);
|
(2)热键消息映射
1
2
3
4
5
6
7
8
|
BEGIN_MESSAGE_MAP(CtestThreadDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
...
ON_MESSAGE(WM_HOTKEY, OnHotKey)
//消息映射
ON_WM_DESTROY()
END_MESSAGE_MAP()
|
(3).h文件中声明热键消息
1
|
afx_msg
LRESULT
OnHotKey(
WPARAM
wparam,
LPARAM
param);
|
(4).cpp文件中编写消息函数
1
2
3
4
5
6
7
8
|
LRESULT
CtestThreadDlg::OnHotKey(
WPARAM
wparam,
LPARAM
lparam)
{
int
a = wparam;
//0x2901
int
b = lparam;
::MessageBox(
this
->GetSafeHwnd(), L
"ok"
, L
"tip"
,0);
return
0;
}
|
(5)注销热键
1
2
3
4
5
|
void
CtestThreadDlg::OnDestroy()
{
CDialogEx::OnDestroy();
UnregisterHotKey(
this
->m_hWnd, 0x2901);
}
|
本文转自Chinayu201451CTO博客,原文链接:http://blog.51cto.com/9233403/1971394
,如需转载请自行联系原作者