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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Command Handler problem in Dialog

Command Handler problem in Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionannouncement
3 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.
  • U Offline
    U Offline
    ugur_basak
    wrote on last edited by
    #1

    in my application, i use some dialogs to update some of the data. I want to add some accelerators. I can add this accelerators in other parts of the application, they work but in dialogs i've a problem. for example when i use Ctrl+A i just got a "beep", it doesn't even "OnEditSelectAll" use this function. How can i use accelerators with Dialogs.

    J 1 Reply Last reply
    0
    • U ugur_basak

      in my application, i use some dialogs to update some of the data. I want to add some accelerators. I can add this accelerators in other parts of the application, they work but in dialogs i've a problem. for example when i use Ctrl+A i just got a "beep", it doesn't even "OnEditSelectAll" use this function. How can i use accelerators with Dialogs.

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      You can make a dialog use an accelerator resource (say IDR_DLG_ACCELERARATOR) doing the following: Add the following members to your dialog class:

      class CSomeDialog : public CDialog
      {
         // All the normal stuff [...]
       
      private:
         HACCEL m_hAccelTable;
       
      public:
         virtual BOOL PreTranslateMessage(MSG* pMsg);
      };

      Add the following to the dialog constructor

      CSomeDialog::CSomeDialog(/* Constructor parms [...] */)
      {
         // What you already have [...]
       
         m_hAccelTable = LoadAccelerators(
                              AfxGetResourceHandle(),
                              MAKEINTRESOURCE(IDR_DLG_ACCELERARATOR));
      }

      Then add the following function implementation:

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

      Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

      U 1 Reply Last reply
      0
      • J Jose Lamas Rios

        You can make a dialog use an accelerator resource (say IDR_DLG_ACCELERARATOR) doing the following: Add the following members to your dialog class:

        class CSomeDialog : public CDialog
        {
           // All the normal stuff [...]
         
        private:
           HACCEL m_hAccelTable;
         
        public:
           virtual BOOL PreTranslateMessage(MSG* pMsg);
        };

        Add the following to the dialog constructor

        CSomeDialog::CSomeDialog(/* Constructor parms [...] */)
        {
           // What you already have [...]
         
           m_hAccelTable = LoadAccelerators(
                                AfxGetResourceHandle(),
                                MAKEINTRESOURCE(IDR_DLG_ACCELERARATOR));
        }

        Then add the following function implementation:

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

        Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

        U Offline
        U Offline
        ugur_basak
        wrote on last edited by
        #3

        Thank you Jose. it worked. A very pratical solution.

        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