C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-29-2006, 07:19 PM   #1
Registered User
 
Join Date: Sep 2006
Posts: 1
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:
if(StartScreenDisplayed){
Do start screen stuff...}
if(MainGameDisplayed){
Do main game stuff...}
if(SettingsScreenDisplayed){
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.
Kontan is offline   Reply With Quote
Old 09-29-2006, 08:03 PM   #2
Registered User
 
Tonto's Avatar
 
Join Date: Jun 2005
Location: New York
Posts: 1,465
This is one solution.

http://www.thehavok.scene.org/scene/...initd3ddx9.php

That tutorial proposes this

Code:
while(message != QUIT)
{
    if(GetMessageFromQueue())
    {
        SendMessageToMsgProc();
    }
    GameLoop();
}

 

(elsewhere in the code)

HRESULT GameLoop()
{
    switch(CurrentPartOfGame)
    {
    case MainMenu:
        RenderMainMenu();

    case ConfigMenu:
        RenderConfigMenu();

    case Exiting:
        RenderExitScreen();

    case InGame:
        RenderGame();
    }
    
    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: http://www.mvps.org/directx/articles..._game_loop.htm then you can just do what you want.
__________________

╔╗╔╦══╦╗╔╦══╦╗
║╚╝║╔╗║╚╝║╔╗║║
║╔╗║╠╣║╔╗║╠╣╠╣
╚╝╚╩╝╚╩╝╚╩╝╚╩╝

codez http://code.google.com/p/zxcvbn/
Tonto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
General question about Windows resources Boomba Windows Programming 2 07-19-2004 09:36 PM
struct problem and general C question techrolla C Programming 8 01-09-2004 01:37 AM
Newb Question: Petzolds "Programming Windows 5th edition" advice Jubba Windows Programming 7 08-28-2003 10:15 PM
Windows 2000 Professional Compatability Question ... SyntaxBubble Windows Programming 15 08-24-2003 11:33 AM
C++ Question Regarding Windows themyth C++ Programming 3 02-20-2003 08:22 PM


All times are GMT -6. The time now is 04:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22