Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ShadowHunter

closing

This topic is 5434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I run windows XP prof edition, and whenever I write a simple program to display something on the screen, the window opens and closes within a split second, I have tried two compilers and it happens on both. However when I tell the program to wait for input it does what it is supposed to, how do I fix this?

Share this post


Link to post
Share on other sites
Advertisement
The program terminates, and when it terminates, the window closes. To keep the window open, keep the program running (say, by requiring a keystroke before exiting the program).

Share this post


Link to post
Share on other sites
Put system("PAUSE"); at the end of your code so your program waits until you press a key before reaching the end of main

Share this post


Link to post
Share on other sites
if you''re just playing around with something for now, the system pause thing is a good idea. however, if you want to go a better way, you should get in the habit of writing programs as infinite loops that are ended by pressing the ESC key or something.


//example windows program loop (placed somewhere in your WinMain function


while (1) {

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if(msg.message == WM_QUIT) //if message was to quit, exit loop

break;

//handle windows messages

TranslateMessage(&msg);
DispatchMessage(&msg);

} else {

//execute main logic of game here

//every execution of this body of code typically ends

//up being one frame of your program drawn to the screen


}

}



if you wand a bit more in the way of examples for what should go in that main program code block, just check out the first of the NeHe OpenGL tutorials (found on this site in the articles and resources section). the tutorials give a lot more detail to what i''ve just written here.

-me

Share this post


Link to post
Share on other sites
Run it from the MS-DOS console instead of directly from the shortcut. Or, use sleep() for time long enough for you to see it. I think it is under ctime, but may be under windows.h.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!