1.00 1.50 1.51 1.52 | 1.00 2.00 2.10 4.00
WINDOWS | WINDOWS NT
kbprg
The information in this article applies to:
- The Microsoft Foundation Classes (MFC) included with:
- Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, and
1.52
- Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 2.1, and 4.0
SUMMARY
To use accelerators with a modeless dialog box, override the function
"PreTranslateMessage()" in your derived CDialog class.
MORE INFORMATION
To use accelerators with your modeless dialog box, perform the following
steps:
- Create a modeless dialog box. For additional information, please see the
following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q103788
TITLE : Creating a Modeless Dialog Box with MFC Libraries
- Insert this sample code into the files listed above the code:
// .H file with your derived CDialog class
class CModeless : public CDialog
{
.
public:
virtual BOOL PreTranslateMessage(MSG*);
.
};
//.CPP file
BOOL CModeless::PreTranslateMessage(MSG* pMsg)
{
HACCEL hAccel =
((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetAccelTable();
if(!(hAccel &&
::TranslateAccelerator(AfxGetApp()->m_pMainWnd, hAccel, pMsg)))
return CDialog::PreTranslateMessage(pMsg);
else
return TRUE;
}
// MAINFRM.H file, where CMainFrame is the main window class
HACCEL CMainFrame::GetAccelTable() { return m_hAccelTable; }
- Create the accelerators with App Studio, or with Resource View from
the Project Workspace in Visual C++ 32-bit Edition, version 4.0. The
accelerators should be in the IDR_MAINFRAME accelerator table. They
should also have the same ID as the controls or menu items with which
they are associated.
|