Thread: General question from a beginner to Windows C++ programming

  1. #1
    Registered User
    Join Date
    Sep 2006

    General question from a beginner to Windows C++ programming

    I have recently started programming windows in C++ using the general GDI and
    there is something I cannot figure out about message based programming.

    Lets say you are making a game. The game starts with a screen that allows
    you to choose 1 player or 2. You would set up a window in WinMain showing
    this screen, along with a WndProc that would handle the messaages such as
    LBUTTONDOWN. After you chose one player or 2, you would want to clear the
    screen and draw the main game display, thereby having a whole new set of
    messages for this part of the game only. You wouldn't want to know whether
    someone had chosen 1 player or 2 because that screen has already been
    established. You now want to know if they are moving, firing, getting hit by
    aliens etc.

    My question is, do you use the same screen (and WndProc) for both of
    these screens and simply add a ton of flags in the WndProc to see what point
    you are in the game, ie:

    case WM_SIZE:
    Do start screen stuff...}
    Do main game stuff...}
    Do setting screen stuff...}

    Or would you set up a different WndProc for each of the main elements in the
    game, having a different WM_SIZE area in each. If this is the case, would you
    set it up in WinMain, creating a window for the start screen along with
    WndProcStartScreen catering to all of the messages, then destroy this window
    when complete and set up another window with another WndProc right on top of
    it handling all the new messages for the new part of the game?

    Please help, this has been driving me nuts.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    This is one solution.

    That tutorial proposes this

    while(message != QUIT)
    (elsewhere in the code)
    HRESULT GameLoop()
        case MainMenu:
        case ConfigMenu:
        case Exiting:
        case InGame:
        return S_OK;

    But you don't need to cram everything into the handling of one message (it would probably, in fact, be bad in a game to do it in WM_PAINT or something). You should probably make more game oriented handling of things, using peekmessage and processing messages only when you need to and doing your game stuff the rest of the time. Good article: then you can just do what you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General question about Windows resources
    By Boomba in forum Windows Programming
    Replies: 2
    Last Post: 07-19-2004, 09:36 PM
  2. struct problem and general C question
    By techrolla in forum C Programming
    Replies: 8
    Last Post: 01-09-2004, 01:37 AM
  3. Replies: 7
    Last Post: 08-28-2003, 10:15 PM
  4. Windows 2000 Professional Compatability Question ...
    By SyntaxBubble in forum Windows Programming
    Replies: 15
    Last Post: 08-24-2003, 11:33 AM
  5. C++ Question Regarding Windows
    By themyth in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2003, 08:22 PM