BOOL RegisterHotKey( HWND hWnd,//接受热键通知的窗口句柄
int id,// 热键标示
UINT fsModifiers,
// 组合键标示
UINT vk // 虚拟键码);
Parameters
-
hWnd
-
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
- 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.
- 同一个线程中不能有相同的标示,(0x0000-0xBFFF)
- 共享库的范围(0xC000-0xFFFF), 要用 GlobalAddAtom返回标示,避免冲突。 fsModifiers
-
Specifies keys that must be pressed in combination with the key specified by the
nVirtKey parameter in order to generate the WM_HOTKEY message. The
fsModifiers parameter can be a combination of the following values. 组合键码
Value Meaning 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
- Specifies the virtual-key code of the hot key.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
Remarks
When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.
如果某键被按下,系统比较所有注册热键,一旦发现匹配,发送热键消息到注册热键的线程,并放到队首,供下次
循环取走使用
This function cannot associate a hot key with a window created by another thread.
不能跨越线程使用
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.
如果组合键被注册了,就会失败
If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters. 如果这个线程的这个窗体已经注册了某热键,热键标示会代替那个热键