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



Recommended Posts

ShadowHunter    122
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
Palidine    1315
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


//handle windows messages


} 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.


Share this post

Link to post
Share on other sites
sSimontis    100
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

Share this post

Link to post
Share on other sites