Share via


Global Hot Keys

Overview

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 message to that window. For instance, if m_HotKeyCtrl is the 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 = m_HotKeyCtrl.GetHotKey( );
pMainWnd->SendMessage( WM_SETHOTKEY, wKeyAndShift );

Whenever the user presses a global hot key, the window specified receives a 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   Windows Common Controls and MFC Classes