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. Handling KeyDown even on Dialog.

Handling KeyDown even on Dialog.

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

    Why am I not able to handle WM_KEYDOWN on a dialog? Pretranslate is the only way? Also what's the reason the event is not getting dispatched to the dialog?

    S 1 Reply Last reply
    0
    • G grassrootkit

      Why am I not able to handle WM_KEYDOWN on a dialog? Pretranslate is the only way? Also what's the reason the event is not getting dispatched to the dialog?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Probably because the control with focus is getting the messages, not the dialog. Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:

      BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
      {
      if (pMsg->message == WM_KEYDOWN)
      pMsg->hwnd = this->m_hWnd;

      return CDialog::PreTranslateMessage(pMsg);
      }

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      G 1 Reply Last reply
      0
      • S Stuart Dootson

        Probably because the control with focus is getting the messages, not the dialog. Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:

        BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
        {
        if (pMsg->message == WM_KEYDOWN)
        pMsg->hwnd = this->m_hWnd;

        return CDialog::PreTranslateMessage(pMsg);
        }

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        G Offline
        G Offline
        grassrootkit
        wrote on last edited by
        #3

        Thanks for your reply Stuart.

        Stuart Dootson wrote:

        Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:

        I could rather manipulate that the key in pretranslate() itself right?

        Stuart Dootson wrote:

        Probably because the control with focus is getting the messages, not the dialog.

        That was my guess, Just to test that I tried deleting all the controls on the dialog. Just a plain dialog but still it's not getting the event. What could be the reason here?

        S 1 Reply Last reply
        0
        • G grassrootkit

          Thanks for your reply Stuart.

          Stuart Dootson wrote:

          Add your WM_KEYDOWN handler and add this PreTranslateMessage override and you should be good, so long as your dialog is modal:

          I could rather manipulate that the key in pretranslate() itself right?

          Stuart Dootson wrote:

          Probably because the control with focus is getting the messages, not the dialog.

          That was my guess, Just to test that I tried deleting all the controls on the dialog. Just a plain dialog but still it's not getting the event. What could be the reason here?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          grassrootkit wrote:

          I could rather manipulate that the key in pretranslate() itself right?

          Should be fine

          grassrootkit wrote:

          What could be the reason here?

          I don't know - but Spy++ could tell you if the dialog's getting the WM_KEYDOWN messages?

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          G 1 Reply Last reply
          0
          • S Stuart Dootson

            grassrootkit wrote:

            I could rather manipulate that the key in pretranslate() itself right?

            Should be fine

            grassrootkit wrote:

            What could be the reason here?

            I don't know - but Spy++ could tell you if the dialog's getting the WM_KEYDOWN messages?

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            G Offline
            G Offline
            grassrootkit
            wrote on last edited by
            #5

            Okay I'll check them up. Thanks for your responses.

            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