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: