OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
About the Hot Key Control

The THotKey class encapsulates the hot-key control from the Common Control Library.

A hot key is a key combination that the user can press to perform an action quickly. The key combination can consist of a modifier key, such as CTRL, ALT or SHIFT, and an accompanying key, such as a character key, an arrow key or a function key.

THotKey has two constructors: one for creating a new hot key object and one for aliasing a hot-key control which was defined in a dialog resource.

Creating a HotKey Object

To create a new control, use the THotKey(TWindow* parent, int id, int x, int y, int w, int h, TModule* module = 0) constructor.

The following code fragement shows how to create a new hot-key control within a window represented by the class TMyWindow.

TMyWindow::TMyWindow(TWindow* parent) :
TWindow(parent)
{
HotKey = new THotKey(this, ID_HOTKEY, 10, 10, 40, 40);
}
Note
Since the control is newed within the constructor of it's parent object, you need not explictly invoke its Create method. ObjectWindows' autocreate feature will ensure that the control is created after the creation of the parent window.

Aliasing a HotKey Object

To alias a hot-key control from a dialog resource, use the THotKey(TWindow* parent, int resourceId, TModule* module = 0) constructor.

The following code fragment illustrates this:

TMyDialog::TMyDialog(TWindow* parent, TResId resId):TDialog(parent, resId)
{
HotKey = new THotKey(this, IDC_HOTKEY);
}

Setting and Retrieving the Key Combination

The SetHotKey and GetHotKey methods of THotKey allow you to set and retrieve the virtual key code and modifier flags of a hot-key from a hot-key control.

The value returned from the GetHotKey method can be used with the WM_SETHOTKEY message to associate a window with a hot-key. When user presses the hot-key, the system activates the window.

Additional Information

The value retrieved from the hot-key control is not usable with the RegisterHotKey API.

You can customize a hot-key control by specifying invalid key combinations and providing the default modifier. See the SetRules method for more information.