RegisterHotKey
Function function: This function defines a system-wide hot key.
Function prototype: BOOL RegisterHotKey (HWND hWnd, intid, UINT fsModifiers, UINT vk );
Parameters:
HWnd: The Window handle for receiving the WM_HOTKEY message generated by the hotkey. If this parameter is NULL, The WM_HOTKEY message passed to the calling thread must be processed in the message loop.
Id: The identifier that defines the hotkey. Other hotkeys in the call thread cannot use the same identifier. The application must define a value in the 0X0000-0xBFFF range. A shared dynamic link library (DLL) must define a value in the 0xC000-0xFFFF range returned by the value of the globalglobaladdatom function ). To avoid conflicts with hotkeys defined by other dynamic link libraries, a DLL must use the GlobalAddAtom function to obtain the identifier of the hotkey.
FsModifoers: defines the key that must be pressed together with the key defined by the reset rtkey parameter to generate the WM_HOTKEY message. This parameter can be a combination of the following values:
MOD_ALT: you can press any Alt key. MOD_CONTROL: press any Ctrl key.
MOD_SHIFT: you can press any Shift key.
MOD_WIN: you can press any Windows button. These keys can be recorded in Microsoft Windows logs.
Vk: Specifies the virtual key code of the hotkey.
Return Value: if the function is successfully called, a non-O value is returned. If the function call fails, the return value is 0. To obtain more error information, call the GetLastError function.
Note: When a key is terminated, the system searches for the matched key in all hotkeys. Once a matching Hot Key is found, the system will pass the WM_HOTKEY message to the Message Queue of the thread that registers the hot key. The message is sent to the queue header, so it will be removed in the next message loop. This function cannot associate hotkeys with windows created by other threads.
The RegisterHotKey function fails to be called if the specified key has been defined by other hotkeys.
If the windows marked by the hWnd parameter have registered a hotkey with the same identifier as the id Parameter definition, the new values of the fsModifiers and vk parameters will replace the values previously defined by these parameters.
- LRESULT OnHotKey (WPARAM wParam, LPARAM lParam); // hotkey Message Processing Function
- ON_MESSAGE (WM_HOTKEY, & OnHotKey) // registers the message function
- RegisterHotKey (this-> m_hWnd, 0, MOD_CONTROL, 0x57); // this-> m_hWnd current window handle, MOD_CONTROL is CTRL, 0x57 is W key