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. OnChar() in Dialog

OnChar() in Dialog

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

    I have a problem with mapping keys to buttons on the dialog. I tried by catching WM_CHAR message like this void CDialogbasedDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case '1': //do sth break; //... } CDialog::OnChar(nChar, nRepCnt, nFlags); } but it didn't work. The application just beeps when I press '1'.

    C 1 Reply Last reply
    0
    • D dart13

      I have a problem with mapping keys to buttons on the dialog. I tried by catching WM_CHAR message like this void CDialogbasedDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(nChar) { case '1': //do sth break; //... } CDialog::OnChar(nChar, nRepCnt, nFlags); } but it didn't work. The application just beeps when I press '1'.

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

      Does the dialog have keyboard focus ? Did you set a breakpoint ? Your code WILL do nothing when a '1' is pressed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      D 1 Reply Last reply
      0
      • C Christian Graus

        Does the dialog have keyboard focus ? Did you set a breakpoint ? Your code WILL do nothing when a '1' is pressed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        D Offline
        D Offline
        dart13
        wrote on last edited by
        #3

        I put SetFocus() in OnInitDialog(), but I don't know anything about setting a breakpoint. Could you please, just in a few steps, explain me what I need to do?

        C 1 Reply Last reply
        0
        • D dart13

          I put SetFocus() in OnInitDialog(), but I don't know anything about setting a breakpoint. Could you please, just in a few steps, explain me what I need to do?

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

          You shouldn't have to call SetFocus, try removing it. A breakpoint is set with F9 ( from memory ), it's a little black circle on the left of your code. Then if you're in debug mode, when you run your program and it gets to the point where the circle is, it will stop and you can examine the state of memory/variables/etc. and step through code. The point here would just be to see if the code is being reached. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          D 1 Reply Last reply
          0
          • C Christian Graus

            You shouldn't have to call SetFocus, try removing it. A breakpoint is set with F9 ( from memory ), it's a little black circle on the left of your code. Then if you're in debug mode, when you run your program and it gets to the point where the circle is, it will stop and you can examine the state of memory/variables/etc. and step through code. The point here would just be to see if the code is being reached. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            D Offline
            D Offline
            dart13
            wrote on last edited by
            #5

            Ok I see what you mean. I know what debugging breakpoint is. I thought you ment it was some kind of a function or something similar. It doesn't work though. The code doesn't get executed. I did manage, however, to trap keysrokes with PreTranslateMessage() like this BOOL CDialogbasedDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_CHAR) { switch(pMsg->wParam) { case '1': // do sth break; case '2': // do sth break; //.... } return TRUE; } else return CDialog::PreTranslateMessage(pMsg); } and it works. But I guess this is not how it should be done. Is there a better way of trapping keystrokes in dialog?

            C 1 Reply Last reply
            0
            • D dart13

              Ok I see what you mean. I know what debugging breakpoint is. I thought you ment it was some kind of a function or something similar. It doesn't work though. The code doesn't get executed. I did manage, however, to trap keysrokes with PreTranslateMessage() like this BOOL CDialogbasedDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_CHAR) { switch(pMsg->wParam) { case '1': // do sth break; case '2': // do sth break; //.... } return TRUE; } else return CDialog::PreTranslateMessage(pMsg); } and it works. But I guess this is not how it should be done. Is there a better way of trapping keystrokes in dialog?

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

              This plainly means that the message is not getting through to your onChar handler. The question is, why ? Did you remove the SetFocus call ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

              D 1 Reply Last reply
              0
              • C Christian Graus

                This plainly means that the message is not getting through to your onChar handler. The question is, why ? Did you remove the SetFocus call ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                D Offline
                D Offline
                dart13
                wrote on last edited by
                #7

                Yes, i did. But how can I set focus to dialog so it can receive WM_CHAR? I put TRACE macro in OnChar, but I dont get any results in the debug screen.

                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