msg pump design

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • msg pump design

      Hi guys,



      How do I explain my questions under 50 words or less?!

      I have a class called WinApp and a class called Game. Inside both WinApp and Game classes I have a message pump. The Game class uses WinApp as a "Has-A". Problem: I would like to be able to have the Game class handle the messages (keyboard input, mouse moves, etc. ) coming in from the WinApp message pump. Once the Game class gets the messages it will forward those messages to another class (Input class). Some code for you to ponder on:

      class WinApp
      {
      public:
      static LRESULT CALLBACK MsgProc(.....);
      ... other code.
      };


      class Game
      {
      private:
      WinApp myApp;

      pubilc:
      static LRESULT CALLBACK MessagePump(.....);
      void MouseEvent( int iState, bool bBtndown ); // This will get passed to Input class from the msg pump
      void IsKeyDown( char *pKey, bool bIsDown ); // This will get passed to Input class from the msg pump
      void KeyEvent( int EvntCode, int KeyNum, const char pcKeyName ); // This will get passed to Input class from the msg pump
      .... other code.
      };

      Whew.... okay now for the question. Anybody have an idea on a solution? I've tried a global pointer within the Game class ("extern Game *g_pGame;" is in the header file) and used:

      LRESULT CALLBACK WinApp::MsgProc(...)
      case WM_KEYDOWN:
      {
      g_pGame->MsgProc(....); // OPPS. WRONG!
      g_pGame->MessagePump(.....); // Want to use Game msg pump. NOT WinApp msg pump. But I think people know what I'm trying to do :)
      }
      but this does not seem to be working. Does anyone see what I am missing or over looking?


      Thank you.

      S

      (Edited: Fix code example)

      The post was edited 1 time, last by Sabrina ().

    • Sabrina,

      i don't really have an answer for but I do have a question. I'm not being condescending, there is very rarely if ever one right way to design a system. Isn't a Game a WinApp ("Windows Application")? What are gaining by the has-a setup?

      gb
    • RE: msg pump design

      Hey there!

      What isn't working about this? Does the original KEYDOWN not get sent, maybe? There's nearly identical code running in the GameCode source, in GameCode.cpp:

      Source Code

      1. case WM_KEYDOWN:
      2. case WM_KEYUP:
      3. case WM_MOUSEMOVE:
      4. case WM_LBUTTONDOWN:
      5. case WM_LBUTTONUP:
      6. case WM_RBUTTONDOWN:
      7. case WM_RBUTTONUP:
      8. {
      9. //
      10. // See Chapter 9, page 265 for more explanation of this code.
      11. //
      12. if (g_pApp->m_pGame)
      13. {
      14. BaseGame *pGame = g_pApp->m_pGame;
      15. // Note the reverse order! User input is grabbed first from the view that is on top,
      16. // which is the last one in the list.
      17. AppMsg msg;
      18. msg.m_hWnd = hWnd;
      19. msg.m_uMsg = uMsg;
      20. msg.m_wParam = wParam;
      21. msg.m_lParam = lParam;
      22. for(GameViewList::reverse_iterator i=pGame->m_gameViews.rbegin(); i!=pGame->m_gameViews.rend(); ++i)
      23. {
      24. if ( (*i)->VOnMsgProc( msg ) )
      25. {
      26. result = true;
      27. break; // WARNING! This breaks out of the for loop.
      28. }
      29. }
      30. }
      31. break;
      32. }
      Display All
      Mr.Mike
      Author, Programmer, Brewer, Patriot