Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accelerators in a Dialog application

Accelerators in a Dialog application

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    __Cerb
    wrote on last edited by
    #1

    I've added an accelerator, then Ctrl+W then selected my main Dlg class. However, when I run my program and press the keys, the accelerator doesn't work... thanks for help -Mike

    D 1 Reply Last reply
    0
    • _ __Cerb

      I've added an accelerator, then Ctrl+W then selected my main Dlg class. However, when I run my program and press the keys, the accelerator doesn't work... thanks for help -Mike

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you called LoadAccelerators() in the dialog's constructor? You'll also need to override the PreTranslateMessage() method and call TranslateAccelerator() accordingly.


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      _ 1 Reply Last reply
      0
      • D David Crow

        Have you called LoadAccelerators() in the dialog's constructor? You'll also need to override the PreTranslateMessage() method and call TranslateAccelerator() accordingly.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        _ Offline
        _ Offline
        __Cerb
        wrote on last edited by
        #3

        Hmm, can you give me an example please? I'm kinda new... CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CD2HackKitDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } thanks

        D 1 Reply Last reply
        0
        • _ __Cerb

          Hmm, can you give me an example please? I'm kinda new... CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CD2HackKitDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } thanks

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          CTestDlg::CTestDlg(CWnd* pParent) : CDialog(CTestDlg::IDD, pParent)
          {
          m_hAccelTable = LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
          }

          BOOL CTestDlg::PreTranslateMessage( LPMSG pMsg )
          {
          if (NULL != m_hAccelTable)
          {
          if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
          return (TRUE);
          }

          return CDialog::PreTranslateMessage(pMsg);
          

          }


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          _ 1 Reply Last reply
          0
          • D David Crow

            CTestDlg::CTestDlg(CWnd* pParent) : CDialog(CTestDlg::IDD, pParent)
            {
            m_hAccelTable = LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
            }

            BOOL CTestDlg::PreTranslateMessage( LPMSG pMsg )
            {
            if (NULL != m_hAccelTable)
            {
            if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
            return (TRUE);
            }

            return CDialog::PreTranslateMessage(pMsg);
            

            }


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            _ Offline
            _ Offline
            __Cerb
            wrote on last edited by
            #5

            Thanks a lot man

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups