有2钟方法,一种是单键(消息)。另一种是系统键加其他键组合,具体可以看下MSDN上的说明。 RegisterHotKey是后一个的函数。MSDN里的一段: There are two ways to associate a hot key with your app: you can use WM_SETHOTKEY to set a single hot key that activates your app, or you can use RegisterHotKey to register any number of hot keys that can do whatever you want. With WM_SETHOTKEY, the key is associated with your top-level window and main thread; RegisterHotKey works with any window and thread. Since WM_SETHOTKEY is the easy approach, I'll show you the other one—RegisterHotKey. But before I do, here are some words of caution: a lot of people (myself included) use text editors like Emacs, which uses virtually every possible combination of Alt + Shift + Ctrl characters fathomable, and we folks get extremely irritated when some program comes along to take over even one of these keys. Imagine—you press Ctrl+Alt+S expecting to invoke regex-search (regular expression search), but instead you get some dialog appearing in the middle of your screen. Sheesh! It's very annoying. So at the least you should provide a way for users to change the hot key or turn it off completely. // In CMyDialog::OnInitDialog m_nIDHotKey = GlobalAddAtom("FileType2App"); RegisterHotKey(m_hWnd, m_nIDHotKey, MOD_WIN, 'A'); 然后ON_MESSAGE(WM_HOTKEY, OnHotKey) 最后void CMyDialog::OnDestroy() { UnregisterHotKey(m_hWnd, m_nIDHotKey); }
http://www.xiaozhou.net/cooldog/blogview.asp?logID=78
RegisterHotKey是后一个的函数。MSDN里的一段:
There are two ways to associate a hot key with your app: you can use WM_SETHOTKEY to set a single hot key that activates your app, or you can use RegisterHotKey to register any number of hot keys that can do whatever you want. With WM_SETHOTKEY, the key is associated with your top-level window and main thread; RegisterHotKey works with any window and thread. Since WM_SETHOTKEY is the easy approach, I'll show you the other one—RegisterHotKey.
But before I do, here are some words of caution: a lot of people (myself included) use text editors like Emacs, which uses virtually every possible combination of Alt + Shift + Ctrl characters fathomable, and we folks get extremely irritated when some program comes along to take over even one of these keys. Imagine—you press Ctrl+Alt+S expecting to invoke regex-search (regular expression search), but instead you get some dialog appearing in the middle of your screen. Sheesh! It's very annoying. So at the least you should provide a way for users to change the hot key or turn it off completely.
// In CMyDialog::OnInitDialog
m_nIDHotKey = GlobalAddAtom("FileType2App");
RegisterHotKey(m_hWnd, m_nIDHotKey, MOD_WIN,
'A');
然后ON_MESSAGE(WM_HOTKEY, OnHotKey)
最后void CMyDialog::OnDestroy()
{
UnregisterHotKey(m_hWnd, m_nIDHotKey);
}