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. Key messages in Dialog app

Key messages in Dialog app

Scheduled Pinned Locked Moved C / C++ / MFC
game-devhelp
7 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.
  • A Offline
    A Offline
    AslFunky
    wrote on last edited by
    #1

    Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky

    A N 2 Replies Last reply
    0
    • A AslFunky

      Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky

      A Offline
      A Offline
      Arsalan Malik
      wrote on last edited by
      #2

      Hint: Handle PreTranslateMessage(MSG* pMsg) filter the message WM_KEYDOWN:cool: ARSALAN MALIK

      A 1 Reply Last reply
      0
      • A Arsalan Malik

        Hint: Handle PreTranslateMessage(MSG* pMsg) filter the message WM_KEYDOWN:cool: ARSALAN MALIK

        A Offline
        A Offline
        AslFunky
        wrote on last edited by
        #3

        Thankx for replying. I think i am understanding what you are talking about. I have checked the MSDN and it has three versions of PreTranslateMessage(), namely: CWinApp, CWinThread and CWnd. It certainly cannot be CWinThread. Which of the remaining two should I handle? I hope it is the CWinApp! Can i do it as: BOOL bHandleNow = FALSE; switch (lpmsg->message) { case WM_KEYDOWN: switch (lpmsg->wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: bHandleNow = TRUE; break; } if (bHandleNow) OnKeyDown(lpmsg->wParam, LOWORD(lpmsg ->lParam), HIWORD(lpmsg->lParam)); break; } return bHandleNow; Please, it would be a lot of help. ;)Thanx in advance;)! AslFunky

        A 1 Reply Last reply
        0
        • A AslFunky

          Hi guys :-O, the other day i was developing a game(the snake game, as in Nokia cellphones) in a dialog based application. I encountered a serious problem X| , when i wasn't able to track the keyoard events for the arrow keys(VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). I have used all possible means, like OnKeyDown() and OnChar() but there is no result:eek:. Can anyone tell me where i am going wrong. ;)Thanx in advance.;) AslFunky

          N Offline
          N Offline
          namaskaaram
          wrote on last edited by
          #4

          maybe u dont get the keyz coz u have some other (control or) window on ut dialog box...... that can be the reason,have u tried SetFocus()??? hope that helpz..... happy programmin..... cheerz..... :-D

          A 1 Reply Last reply
          0
          • A AslFunky

            Thankx for replying. I think i am understanding what you are talking about. I have checked the MSDN and it has three versions of PreTranslateMessage(), namely: CWinApp, CWinThread and CWnd. It certainly cannot be CWinThread. Which of the remaining two should I handle? I hope it is the CWinApp! Can i do it as: BOOL bHandleNow = FALSE; switch (lpmsg->message) { case WM_KEYDOWN: switch (lpmsg->wParam) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: bHandleNow = TRUE; break; } if (bHandleNow) OnKeyDown(lpmsg->wParam, LOWORD(lpmsg ->lParam), HIWORD(lpmsg->lParam)); break; } return bHandleNow; Please, it would be a lot of help. ;)Thanx in advance;)! AslFunky

            A Offline
            A Offline
            Arsalan Malik
            wrote on last edited by
            #5

            For dialog based MFC application, add PreTranslateMessage as virtual function from class menu. ARSALAN MALIK

            A 1 Reply Last reply
            0
            • N namaskaaram

              maybe u dont get the keyz coz u have some other (control or) window on ut dialog box...... that can be the reason,have u tried SetFocus()??? hope that helpz..... happy programmin..... cheerz..... :-D

              A Offline
              A Offline
              AslFunky
              wrote on last edited by
              #6

              Hi, thanx for replying. Yes, i have tried using SetFocus(), but that doesn't work. Anyway, Arsalan Malik has given the right solution. We must override the virtual function PreTranslateMessage() of the CWnd class. In this code we have to return a TRUE for the keydown messages if they are VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT. These are stored in the HIWORD and LOWORD of the message of the lpMsg paramater. Please refer to MSDN if you cannot get this. It is quite clear there. Thanx anyway. Bye /--------\ |AslFunky| \--------/

              1 Reply Last reply
              0
              • A Arsalan Malik

                For dialog based MFC application, add PreTranslateMessage as virtual function from class menu. ARSALAN MALIK

                A Offline
                A Offline
                AslFunky
                wrote on last edited by
                #7

                Oh, you got it all wrong. What i meant was, which class's PreTranslateMessage() should i override, since PreTranslateMessage() is a virtual function in three classes. Anyway, i have got the answer, we must override the CWnd class's function. ;) Thanx a lot for helping me out. That was a real relief ;) /--------\ |AslFunky| \--------/

                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