Use the accelerator key in the MFC Dialog Box program

Source: Internet
Author: User

Create a dialog box-based project and add a button, modify the button ID. Here it is id_btn_openfile, and add a message RESPONSE event for the button. Here I open the file save dialog box:

 void cacceldlg: onbtnopenfile () {// todo: add your control notification handler code herecfiledialog DLG (true); DLG. domodal () ;}
adds an acceleration key resource for the project. Note that the ID must be the same as the button ID, only in this way can the association be generated

Add an acceleration key variable member to the Main Dialog Box class:

 haccel m_haccel; 
load the acceleration key resource in the oninitdialog initialization function of the dialog box

 // load the acceleration key resource m_haccel = loadaccelerators (AfxGetInstanceHandle (), makeintresource (idr_accelerator1); 

however, to process a key in the dialog box, you need to process the key message, translate the key, and add a virtual function: pretranslagemessage: Add a translation function for the acceleration key in the function

 translateaccelerator (m_hwnd, m_haccel, PMSG); 

OK. Press Ctrl + O to achieve the same effect as clicking open:


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.