game loop

This is a discussion on game loop within the Windows Programming forums, part of the Platform Specific Boards category; im trying to setup a game loop but without using an actual window: Code: int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    game loop

    im trying to setup a game loop but without using an actual window:

    Code:
    int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow)
    {
    	HWND hInvisible = CreateWindow("Static", "", 0, 0, 0, 0, 0, 0, 0, hInst, 0);
    
    	//Init with hInvisible as window
    
    	while (bRunning)
    	{
    		//...game loop
    	}
    
    	//DeInit
    }
    i was wondering, is there any disadvantages to the method i use? in all the directx examples ive seen, they set up a window.. but since my program doesnt need a window, i figured this way would be alot better?

    when i run the program, it immediately goes to fullscreen instead of showing a window, and i handle all the keys (alt + f4 and esc.. etc) in my game loop...

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Why make a call to CreateWindow() at all if you dont need a window?

    Code:
    int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow)
    {
        while (bRunning)
        {
            //...game loop
        }
    
        //DeInit
    }

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    the directx createdevice function needs a hwnd handle.. i tried giving it 0 (desktop) but that didnt work..

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I'm not 100% but....

    A possible problem is the messages sent to your window.

    That is 'statics' don't respond (generate a msg) to some user actions. Other controls generate and respond in different ways to other msgs (ie you may need to catch EN_CHANGE msgs instead of WM_KEYDOWN/CHAR, if you used an edit).

    Why not create a window 1x1 that is not visible?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    the thing is, i dont need to catch any messages.. i just check for them using direct input and only allow the keypresses i want.. e.g. disable all ALT keys except for alt-tab and alt-f4...

    and is there really a point in making a 1x1 window if im not going to need the messages?

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I'm just giving suggestions...never tried this so is all conjecture.

    >>i dont need to catch any messages..

    Its more about the messages that the control generates and you don't handle or the way the OS passes on msgs to your app (ie bypassing msg que and posted directly).

    >>and is there really a point in making a 1x1 window if im not going to need the messages?

    I would consider it better style....but nothing concrete (as I said above)


    Only one way to find out........
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    19
    Quote Originally Posted by X PaYnE X
    the directx createdevice function needs a hwnd handle.. i tried giving it 0 (desktop) but that didnt work..
    0 != desktop The desktop handle is not zero which would imply that it's NULL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  4. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM

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