Condividi tramite


Global Hot Keys

A global hot key is associated with a particular nonchild window. It allows the user to activate the window from any part of the system. An application sets a global hot key for a particular window by sending the WM_SETHOTKEY message to that window. For instance, if m_HotKeyCtrl is the CHotKeyCtrl object and pMainWnd is a pointer to the window to be activated when the hot key is pressed, you could use the following code to associate the hot key specified in the control with the window pointed to by pMainWnd.

WORD wKeyAndShift = static_cast<WORD>(m_HotKeyCtrl.GetHotKey());
this->SendMessage(WM_SETHOTKEY, wKeyAndShift);   

Whenever the user presses a global hot key, the window specified receives a WM_SYSCOMMAND message that specifies SC_HOTKEY as the type of the command. This message also activates the window that receives it. Because this message does not include any information on the exact key that was pressed, using this method does not allow distinguishing between different hot keys that may be attached to the same window. The hot key remains valid until the application that sent WM_SETHOTKEY exits.

See Also

Reference

Using CHotKeyCtrl

Concepts

Controls (MFC)