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. hotkeys on a dialog

hotkeys on a dialog

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 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.
  • Q Offline
    Q Offline
    Qadddd
    wrote on last edited by
    #1

    hello, I would like to type a shortcut on my dialog and that it executes a particular routine I have coded (ie set the focus on a particular input control). I have no menu on my dialog window . How should I do this ? I have created a accelerator to set my shortcut, linked the accelerator to my code using the class wizard, but when I launch my appli, nothing happens when I press my shortcut ... What is missing ? Is it the correct way to do this ? Thanks in advance DD

    I 1 Reply Last reply
    0
    • Q Qadddd

      hello, I would like to type a shortcut on my dialog and that it executes a particular routine I have coded (ie set the focus on a particular input control). I have no menu on my dialog window . How should I do this ? I have created a accelerator to set my shortcut, linked the accelerator to my code using the class wizard, but when I launch my appli, nothing happens when I press my shortcut ... What is missing ? Is it the correct way to do this ? Thanks in advance DD

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.

      Q 2 Replies Last reply
      0
      • I Iain Clarke Warrior Programmer

        I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.

        Q Offline
        Q Offline
        Qadddd
        wrote on last edited by
        #3

        Yes, seems to be exactly what I need. I an going to try it immediatly Thanks for help. DD

        1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          I did a quick search for "dialog AND accelerator" in MSDN and came up with the following: Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box which should give you exactly what you want. Classwizard won't help you much though... I don't remember the last time I used CW! Iain.

          Q Offline
          Q Offline
          Qadddd
          wrote on last edited by
          #4

          yes, it works but ... what happens when I defined several keys combinations in my accelerator, as it can be considered as a table of keystrokes. I loaded my accelerator table in the OnInitDialog() : m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1)); These special keystroke can be recognized in the override routine : BOOL CDialogDlg::PreTranslateMessage(MSG* pMsg) if (m_hAccelTable) { if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) { return(TRUE); } } return CDialog::PreTranslateMessage(pMsg); } What I understood is that, when ::TranslateAccelerator recognizes a keystroke existing in accelerator, it send a WM_COMMAND message. Then, using class wizard, I created a routine corresponding to dialog IDR_ACCELERATOR1-WM_COMMAND message: void CDialogDlg::OnAccelerator1() { GetDlgItem(IDC_EDIT3)->SetFocus(); //special keystroke => set focus here } It works, but how can I perform different actions depending on keystroke? Can I get the keystroke or is there any way to distinguish them? Should I have several Accelerator and load them all and perform the ::TranslateAccelerator on each of them? Could you still give me some help on this? Thanks in advance DD

          I 1 Reply Last reply
          0
          • Q Qadddd

            yes, it works but ... what happens when I defined several keys combinations in my accelerator, as it can be considered as a table of keystrokes. I loaded my accelerator table in the OnInitDialog() : m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1)); These special keystroke can be recognized in the override routine : BOOL CDialogDlg::PreTranslateMessage(MSG* pMsg) if (m_hAccelTable) { if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg)) { return(TRUE); } } return CDialog::PreTranslateMessage(pMsg); } What I understood is that, when ::TranslateAccelerator recognizes a keystroke existing in accelerator, it send a WM_COMMAND message. Then, using class wizard, I created a routine corresponding to dialog IDR_ACCELERATOR1-WM_COMMAND message: void CDialogDlg::OnAccelerator1() { GetDlgItem(IDC_EDIT3)->SetFocus(); //special keystroke => set focus here } It works, but how can I perform different actions depending on keystroke? Can I get the keystroke or is there any way to distinguish them? Should I have several Accelerator and load them all and perform the ::TranslateAccelerator on each of them? Could you still give me some help on this? Thanks in advance DD

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            Real life slowed my reply. You can set various key combinations in the accelerator, each associated with a command value. e.g.

            ALT-Q => IDC_Q
            CTRL-j => IDC_J

            In your dlgs message map you would have

            ON_COMMAND(IDC_Q, OnQ)
            ON_COMMAND(IDC_Q, OnQ)

            (I never use class wizard, as it runs into too many limitations, e.g. ON_COMMAND_RANGE()) If you are only using the accelerator for settings focus on other controls, you can just put a static control before them in the tab order with one of the keys underlined (i.e. Qeue: _______. When you press Alt Q, the dialog tries to put focus on the static control, which then puts in on the next control with the WS_TABSTOP style. So you may not need the accelerator after all! Iain.

            Q 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Real life slowed my reply. You can set various key combinations in the accelerator, each associated with a command value. e.g.

              ALT-Q => IDC_Q
              CTRL-j => IDC_J

              In your dlgs message map you would have

              ON_COMMAND(IDC_Q, OnQ)
              ON_COMMAND(IDC_Q, OnQ)

              (I never use class wizard, as it runs into too many limitations, e.g. ON_COMMAND_RANGE()) If you are only using the accelerator for settings focus on other controls, you can just put a static control before them in the tab order with one of the keys underlined (i.e. Qeue: _______. When you press Alt Q, the dialog tries to put focus on the static control, which then puts in on the next control with the WS_TABSTOP style. So you may not need the accelerator after all! Iain.

              Q Offline
              Q Offline
              Qadddd
              wrote on last edited by
              #6

              Thanks for answer on accelerator and the good idea the trick of the static control !! I will use it ! Bye

              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