Microsoft small business knowledge base

Article ID: 117500 - Last Review: October 26, 2013 - Revision: 4.0

This article was previously published under Q117500
This article has been archived. It is offered "as is" and will no longer be updated.


To use accelerators with a modeless dialog box, override the PreTranslateMessage()function in your derived CDialog class.

More information

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

  1. 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
  2. Insert this sample code into the files listed above the code:
       // .h file with your derived CDialog class.
       class CModeless : public CDialog
          virtual BOOL PreTranslateMessage(MSG*);
       //.cpp file.
       BOOL CModeless::PreTranslateMessage(MSG* pMsg)
          HACCEL hAccel =
          if(!(hAccel &&
               ::TranslateAccelerator(AfxGetApp()->m_pMainWnd->m_hWnd, hAccel,
               return CDialog::PreTranslateMessage(pMsg);
             return TRUE;
       // Mainfrm.h file, where CMainFrame is the main window class.
       HACCEL CMainFrame::GetAccelTable() { return m_hAccelTable; }
  3. 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.

Applies to
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.52 Professional Edition
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 4.0 Standard Edition
kbnosurvey kbarchive kbacceleratorkey kbarchitecture kbdlg kbinfo kbkeyaccel kbuidesign KB117500
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support