Defining global shortcut keys for programs in VC/MFC

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.