Adding accelerators (shortcuts) to MFC - HOW?

I found this link: http://support.microsoft.com/kb/222829

But I can’t understand this.

Ok, I realized that I need to add this to my header file:

HACCEL  m_hAccelTable;

and then this:

m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));

to my main .cpp

But where does it go?

BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg) {
   if (m_hAccelTable) {
      if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) {
         return(TRUE);
      }
   }
   return CDialog::PreTranslateMessage(pMsg);

}

I need about 6 shortcuts (CTRL + U to load something, CTRL + O to load smth else), I do not understand how this works, I need a little help

+3
source share
2 answers

Now the MSDN article is misleading. It shows how to add accelerators to the "About" field, and only the "O" field will be able to process the accelerator, which in this case is equivalent to pressing a button with IDC_BUTTON1 ID.

- , . MDI/SDI.

, : Accelerator, , . , , ID. , , . : HACCEL . InitInstance LoadAccelerators. PreTranslateMessage . :

      if (m_hAccelTable) 
      {
                if (::TranslateAccelerator(*m_pMainWnd, m_hAccelTable, pMsg)) 
                {
                          return(TRUE);
                }
      }

. * m_pMainWnd. ( ). . , OnCmdMsg.

. , SDI CFormView. , , , ., , , , .

+11

, , , .

MFC ?

, , , PreTranslateMessage.

, CFrameWnd:: LoadAccelTable.

0

All Articles