如何注册系统热键
2006-08-03 14:44
316 查看
使用函数RegisterHotKey,其原型为:
Parameters
hWnd [in] Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop. id [in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier. fsModifiers [in] Specifies keys that must be pressed in combination with the key specified by the uVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values. MOD_ALT Either ALT key must be held down. MOD_CONTROL Either CTRL key must be held down. MOD_SHIFT Either SHIFT key must be held down. MOD_WIN Either WINDOWS key was held down. These keys are labeled with the Microsoft® Windows® logo.vk [in] Specifies the virtual-key code of the hot key.
使用方法:
如要为一对话框程序注册热键Ctrl+Alt+K
1、在MyDlg.h中 声明消息映射函数 afx_msg LRESULT OnHotKey(WPARAM wParam,LPARAM lParam);
2、在MyDlg.cpp中,定义消息映射
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
...
ON_MESSAGE(WM_HOTKEY,OnHotKey)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3、定义消息映射函数
LRESULT CMyDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if (wParam == 6789) //6789为调用RegisterHotKey时指定的热键对应的id
{
AfxMessageBox("you pressed hotkey");
}
return 0;
}
4、在合适的地方调用RegisterHotKey
RegisterHotKey(GetSafeHwnd(),6789,MOD_ALT|MOD_CONTROL,'K');
BOOL RegisterHotKey( HWND hWnd, int id, UINT fsModifiers, UINT vk );
Parameters
hWnd [in] Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop. id [in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier. fsModifiers [in] Specifies keys that must be pressed in combination with the key specified by the uVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values. MOD_ALT Either ALT key must be held down. MOD_CONTROL Either CTRL key must be held down. MOD_SHIFT Either SHIFT key must be held down. MOD_WIN Either WINDOWS key was held down. These keys are labeled with the Microsoft® Windows® logo.vk [in] Specifies the virtual-key code of the hot key.
使用方法:
如要为一对话框程序注册热键Ctrl+Alt+K
1、在MyDlg.h中 声明消息映射函数 afx_msg LRESULT OnHotKey(WPARAM wParam,LPARAM lParam);
2、在MyDlg.cpp中,定义消息映射
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
...
ON_MESSAGE(WM_HOTKEY,OnHotKey)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3、定义消息映射函数
LRESULT CMyDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if (wParam == 6789) //6789为调用RegisterHotKey时指定的热键对应的id
{
AfxMessageBox("you pressed hotkey");
}
return 0;
}
4、在合适的地方调用RegisterHotKey
RegisterHotKey(GetSafeHwnd(),6789,MOD_ALT|MOD_CONTROL,'K');
相关文章推荐
- vc 如何注册系统热键
- 【原创】vc 如何注册系统热键
- DELPHI如何注册系统热键
- 如何注册系统热键
- 用DELPHI如何注册系统热键
- vc 如何注册多个系统热键
- B/S模式下如何使软件屏蔽系统热键
- 如何将USBKey中的证书注册到Windows系统中
- 如何更改操作系统属性中注册到系统名
- VB6 注册系统热键
- 如何删除系统已注册的服务
- 注册系统热键
- 注册系统热键
- C# 如何实现热键注册 RegisterHotKey
- 在WPF中如何注册热键(转)
- 有意思的RTL函数RegisterClass(在持久化中,你生成的一个新类的对象,系统并不知道他是如何来的,因此需要你注册)good
- 注册系统热键,调用java程序
- 非安装的tomcat,如何注册成系统服务
- 注册系统热键 RegisterHotKey()
- 如何Tomcat注册成系统服务