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. How can I get WM_KEYDOWN message in the CWnd-derived class?

How can I get WM_KEYDOWN message in the CWnd-derived class?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
17 Posts 3 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.
  • E Eugene Pustovoyt

    I have a CWnd-derived class. In the demo dialog I'm put the object from this class. I'm need to handle an arrow button push in the object of the CWnd-derived class, but I can't retrive a WM_KEYDOWN message. Can somebody help me? Best regards, Eugene Pustovoyt


    ICQ UIN: 161325180

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    You're not getting WM_KEYDOWN at all, or just for the arrow ? Christian Graus - Microsoft MVP - C++

    E 1 Reply Last reply
    0
    • E Eugene Pustovoyt

      I have a CWnd-derived class. In the demo dialog I'm put the object from this class. I'm need to handle an arrow button push in the object of the CWnd-derived class, but I can't retrive a WM_KEYDOWN message. Can somebody help me? Best regards, Eugene Pustovoyt


      ICQ UIN: 161325180

      H Offline
      H Offline
      hamster1
      wrote on last edited by
      #3

      Now what - dialog of CWnd?? With dialogs you'll never get this msg since always a child wnd has the focus. Dig into PreTranslateMessage() instead. ---------------------- ~hamster1

      E 1 Reply Last reply
      0
      • C Christian Graus

        You're not getting WM_KEYDOWN at all, or just for the arrow ? Christian Graus - Microsoft MVP - C++

        E Offline
        E Offline
        Eugene Pustovoyt
        wrote on last edited by
        #4

        I'm not getting WM_KEYDOWN at all, but I need a arrow button only. I'm try to handle a message in the OnKeyDown() handler and in the PreTranslateMessage() method. Best regards, Eugene Pustovoyt


        ICQ UIN: 161325180

        C 1 Reply Last reply
        0
        • E Eugene Pustovoyt

          I'm not getting WM_KEYDOWN at all, but I need a arrow button only. I'm try to handle a message in the OnKeyDown() handler and in the PreTranslateMessage() method. Best regards, Eugene Pustovoyt


          ICQ UIN: 161325180

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #5

          Then something else is swallowing the message - what on the dialog has the focus ? Christian Graus - Microsoft MVP - C++

          E 1 Reply Last reply
          0
          • H hamster1

            Now what - dialog of CWnd?? With dialogs you'll never get this msg since always a child wnd has the focus. Dig into PreTranslateMessage() instead. ---------------------- ~hamster1

            E Offline
            E Offline
            Eugene Pustovoyt
            wrote on last edited by
            #6

            I'm understand, but how can I set a focus, if SetFocus() method has not effect. In the PreTranslateMessage() method I don't retrive a WM_KEYDOWN message too. Best regards, Eugene Pustovoyt


            ICQ UIN: 161325180

            1 Reply Last reply
            0
            • C Christian Graus

              Then something else is swallowing the message - what on the dialog has the focus ? Christian Graus - Microsoft MVP - C++

              E Offline
              E Offline
              Eugene Pustovoyt
              wrote on last edited by
              #7

              Yes, dialog has the focus. By press arrow button has effect in the last focused window (for example - CListBox). If I press TAB then after some steps I jump to the my CWnd::OnFocus() method. Best regards, Eugene Pustovoyt


              ICQ UIN: 161325180

              C 1 Reply Last reply
              0
              • E Eugene Pustovoyt

                Yes, dialog has the focus. By press arrow button has effect in the last focused window (for example - CListBox). If I press TAB then after some steps I jump to the my CWnd::OnFocus() method. Best regards, Eugene Pustovoyt


                ICQ UIN: 161325180

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #8

                Eugene Pustovoyt wrote: Yes, dialog has the focus. By press arrow button has effect in the last focused window (for example - CListBox). Then, the dialog does not have the focus. How is this window being shown, is it a modeless dialog ? Christian Graus - Microsoft MVP - C++

                E 1 Reply Last reply
                0
                • C Christian Graus

                  Eugene Pustovoyt wrote: Yes, dialog has the focus. By press arrow button has effect in the last focused window (for example - CListBox). Then, the dialog does not have the focus. How is this window being shown, is it a modeless dialog ? Christian Graus - Microsoft MVP - C++

                  E Offline
                  E Offline
                  Eugene Pustovoyt
                  wrote on last edited by
                  #9

                  No, it's modal dialog Best regards, Eugene Pustovoyt


                  ICQ UIN: 161325180

                  C 1 Reply Last reply
                  0
                  • E Eugene Pustovoyt

                    No, it's modal dialog Best regards, Eugene Pustovoyt


                    ICQ UIN: 161325180

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #10

                    Then how can you be pressing tab to move the focus into the dialog ? Or did I misunderstand you ? Christian Graus - Microsoft MVP - C++

                    E 1 Reply Last reply
                    0
                    • C Christian Graus

                      Then how can you be pressing tab to move the focus into the dialog ? Or did I misunderstand you ? Christian Graus - Microsoft MVP - C++

                      E Offline
                      E Offline
                      Eugene Pustovoyt
                      wrote on last edited by
                      #11

                      You're misunderstand me. When I press TAB then focus jump by all controls of the MODAL dialog and to my control (OnSetFocus method) too. Therefore I think a dialog do process WM_KEYDOWN message, but this message isn't arrive at my CWnd-derived class. Best regards, Eugene Pustovoyt


                      ICQ UIN: 161325180

                      C 1 Reply Last reply
                      0
                      • E Eugene Pustovoyt

                        You're misunderstand me. When I press TAB then focus jump by all controls of the MODAL dialog and to my control (OnSetFocus method) too. Therefore I think a dialog do process WM_KEYDOWN message, but this message isn't arrive at my CWnd-derived class. Best regards, Eugene Pustovoyt


                        ICQ UIN: 161325180

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #12

                        Oh - is your CWnd derived class a control on the dialog ? If that's the case, then the fact you need to press tab proves that your control does not have focus, and therefore does not get any keyboard messages. Christian Graus - Microsoft MVP - C++

                        E 1 Reply Last reply
                        0
                        • C Christian Graus

                          Oh - is your CWnd derived class a control on the dialog ? If that's the case, then the fact you need to press tab proves that your control does not have focus, and therefore does not get any keyboard messages. Christian Graus - Microsoft MVP - C++

                          E Offline
                          E Offline
                          Eugene Pustovoyt
                          wrote on last edited by
                          #13

                          Yes, my CWnd-derived class is a control on the dialog. And how can set focus if SetFocus() method has not effect or how can I get WM_KEYDOWN message?? Best regards, Eugene Pustovoyt


                          ICQ UIN: 161325180

                          C 1 Reply Last reply
                          0
                          • E Eugene Pustovoyt

                            Yes, my CWnd-derived class is a control on the dialog. And how can set focus if SetFocus() method has not effect or how can I get WM_KEYDOWN message?? Best regards, Eugene Pustovoyt


                            ICQ UIN: 161325180

                            C Offline
                            C Offline
                            Christian Graus
                            wrote on last edited by
                            #14

                            To get the message, you need the focus. Can't you set your control to be the one that recieves initial focus in the dialog editor ? Perhaps making it top of the tab order will do this ? Christian Graus - Microsoft MVP - C++

                            E 1 Reply Last reply
                            0
                            • C Christian Graus

                              To get the message, you need the focus. Can't you set your control to be the one that recieves initial focus in the dialog editor ? Perhaps making it top of the tab order will do this ? Christian Graus - Microsoft MVP - C++

                              E Offline
                              E Offline
                              Eugene Pustovoyt
                              wrote on last edited by
                              #15

                              In my OnSetFocus() handler I call CWnd::OnSetFocus(pOldWnd) and just SetFocus(), but it has not effect to getting WM_KEYDOWN message. How another I can set a focus? Best regards, Eugene Pustovoyt


                              ICQ UIN: 161325180

                              C 1 Reply Last reply
                              0
                              • E Eugene Pustovoyt

                                In my OnSetFocus() handler I call CWnd::OnSetFocus(pOldWnd) and just SetFocus(), but it has not effect to getting WM_KEYDOWN message. How another I can set a focus? Best regards, Eugene Pustovoyt


                                ICQ UIN: 161325180

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #16

                                Which OnSetFocus handler ? YOu're saying you call OnSetFocus in the dialog, and the handler in your control calls it as well, as it's a composite control ? Christian Graus - Microsoft MVP - C++

                                E 1 Reply Last reply
                                0
                                • C Christian Graus

                                  Which OnSetFocus handler ? YOu're saying you call OnSetFocus in the dialog, and the handler in your control calls it as well, as it's a composite control ? Christian Graus - Microsoft MVP - C++

                                  E Offline
                                  E Offline
                                  Eugene Pustovoyt
                                  wrote on last edited by
                                  #17

                                  Probably it because my bad English. Start from begin step by step: 1. I wrote a Cwnd-derived control which must to get a WM_KEYDOWN 2. I'm put his to MODAL DEMO DIALOG 3. If I press TAB in my demo then I see as a focus jump from the control to the control. Focus also jump into WM_SETFOCUS handler of the my control CMyControl::OnSetFocus() 4. In the WM_SETFOCUS handler of the my control I call CWnd::OnSetFocus() or SetFocus() but it has not effect to getting a WM_KEYDOWN message. I can't get this message neither in the WM_KEYDOWN handler of the CMyControl nor in the CMyControl::PreTranslateMessage. Best regards, Eugene Pustovoyt


                                  ICQ UIN: 161325180

                                  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