Enable Accelerator for Dialog Application in MFC(HowTo)
Saturday, June 30, 2007 by HongJunX
(This method is from Microsoft MSDN)
1.Add the class member variable accelTable to your Dialog class:
HACCEL accelTable;
2.Add the code below in the According Dialog constructor:
accelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
3.Press Ctrl+W to open class-wizard,in the object IDs column,choose your dialog,then double click the PreTranslateMessage message in the Messages column.This will add the PreTranslateMessage to your app.Press edit button and add the green code below:
BOOL YourDlg::PreTranslateMessage(MSG* pMsg)
{
if (accelTable) {
if (::TranslateAccelerator(m_hWnd, accelTable, pMsg)) {
return(TRUE);
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Ok,rebuilt your project,and run.
It works for me~
1.Add the class member variable accelTable to your Dialog class:
HACCEL accelTable;
2.Add the code below in the According Dialog constructor:
accelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
3.Press Ctrl+W to open class-wizard,in the object IDs column,choose your dialog,then double click the PreTranslateMessage message in the Messages column.This will add the PreTranslateMessage to your app.Press edit button and add the green code below:
BOOL YourDlg::PreTranslateMessage(MSG* pMsg)
{
if (accelTable) {
if (::TranslateAccelerator(m_hWnd, accelTable, pMsg)) {
return(TRUE);
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Ok,rebuilt your project,and run.
It works for me~
0 Comments:
Post a Comment