Microsoft KB Archive/117500

= INFO: Using Accelerators with an MFC Modeless Dialog Box =

Article ID: 117500

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q117500

<div class="summary_section">

SUMMARY
To use accelerators with a modeless dialog box, override the PreTranslateMessagefunction in your derived CDialog class.

<div class="moreinformation_section">

MORE INFORMATION
To use accelerators with your modeless dialog box, perform the following steps:

<ol> Create a modeless dialog box. For additional information, please see the following article in the Microsoft Knowledge Base:

103788 Creating a Modeless Dialog Box with MFC Libraries

</li>  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->m_hWnd, 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; } </li> 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.</li></ol>

Additional query words: kbinf 1.00 1.50 1.51 1.52 2.00 2.10 2.50 2.51 2.52 3.00 3.10 4.00

Keywords: kbinfo kbuidesign kbarchitecture kbkeyaccel kbdlg kbacceleratorkey KB117500

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.