VC 2010-05-01 18:01:34 Read 287 comments 0 font size: big Middle small Subscription
1. Register shortcut keys
In the initialization function, such as OnInitDialog () register the shortcut key, the code is as follows:
#define HOTKEYID1 200
BOOL Cdlgcloseprosetup::oninitdialog ()
{
CDialog::OnInitDialog ();
:: RegisterHotKey (M_hwnd, HotKeyID1, NULL, vk_home);
return TRUE;
}
RegisterHotKey () The first parameter is a handle, the second is the accelerator ID number, can be arbitrarily defined, the third is a control key, if not required to be set to NULL, the fourth is a letter or a number, the same does not need to be set to null.
2. Add the following message:
3. Write in the Onhotkey function
void Cjseditdlg::onhotkey (UINT Nhotkeyid, uint nKey1, uint nKey2)
{
TODO: Add Message Handler code and/or call default values here
if (Nhotkeyid = = HotKeyID1)
{
Onbnclickedbtnkill ();
}
Cdialog::onhotkey (Nhotkeyid, NKey1, NKey2);
}
4. Add a WM_CLOSE message to write in the OnClose function
void Cjseditdlg::onclose ()
{
TODO: Add Message Handler code and/or call default values here
Unregisterhotkey (GetSafeHwnd (), HotKeyID1);
Cdialog::onclose ();
}
Defining global shortcut keys for programs in VC/MFC