Sign in to follow this  

What is wrong with my app?

This topic is 4239 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 made a very simple app in WinAPI. When I run it, a process starts. When I close it (click the X) it ends but the process is still running and seen in my manager! I was looking through the Net for a possible explanation but no one seems to know why this is happening. Any ideas?

Share this post


Link to post
Share on other sites
Well I use SDL to make games and I've had a similar problem. It lies in the logic you use to decide whether or not the game is over. Typically the problem is that you exit the API, but the code behind it is still being executed. Posting your code could probably help.

Share this post


Link to post
Share on other sites
You are most likely closing the window but not stopping your main loop.

Share this post


Link to post
Share on other sites
There's a large difference between the window of the process and the actual process. You need to check the messages your window gets to find the signal that your window was closed and respond to that by quitting your actual process (for instance, by returning 0 in WinMain).

A number of my programs use such an inner-loop in the main cycle:

while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
return 0;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}


Of course, this implies that this cycle is either in WinMain or a function that, when it returns 0, closes the program.

If you don't know about reading Windows messages, you're going to have to look into that :)

Share this post


Link to post
Share on other sites
and you could always just do a PostQuitMessage(0); whenever you are trying to close the program, this should take care of it.

Share this post


Link to post
Share on other sites
I had the PostQuitMessage(0); line, and my loop was also finished. But there were some differences in my WinMain... Changed it and now it works :) Thanx guys for all feedback!

Share this post


Link to post
Share on other sites
Sign in to follow this