Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This topic demonstrates how to retrieve or set the key combination for a hot key control. The HKM_SETHOTKEY message allows an application to set the hot key combination for a hot key control. Applications use the HKM_GETHOTKEY message to retrieve the virtual key code and modifier flags of the hot key that is chosen by the user.
What you need to know
Technologies
Prerequisites
- C/C++
- Windows User Interface Programming
Instructions
Use the HKM_GETHOTKEY message to retrieve the virtual key code and modifier keys that describe a hot key chosen by the user. Use the HKM_SETHOTKEY message to set those values for a hot key.
In the following C++ code example, the application-defined function uses the HKM_GETHOTKEY message to retrieve a key combination from a hot key control and then uses the WM_SETHOTKEY message to set a global hot key. Note that you cannot set a global hot key for a window that has the WS_CHILD window style.
// Retrieves the hot key from the hot key control and sets it as
// the hot key for the application's main window.
//
// Parameters
// hwndHot - Handle of the hot key control.
// hwndMain - Handle of the main window.
BOOL WINAPI ProcessHotkey(HWND hwndHot, HWND hwndMain)
{
WORD wHotkey;
// Retrieve the hot key (virtual key code and modifiers).
wHotkey = (WORD) SendMessage(hwndHot, HKM_GETHOTKEY, 0, 0);
// Use the result as wParam for WM_SETHOTKEY.
SendMessage(hwndMain, WM_SETHOTKEY, wHotkey, 0);
return TRUE;
}
Related topics