Archived

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

Kojo

Why?

Recommended Posts

I have a win32 program that was running fine, window opened and program ran, window closed and program stopped. However, the program is no longer exiting... The window closes and it disapears from windows task manager's "Applications" list, but it remains on the processes list.... why? Has anyone had any experiences anything like this before? EDIT : forgot... this causes the computer to run very slowly after the program is closed and is just generally a pain. [edited by - Kojo on May 19, 2004 7:56:47 PM]

Share this post


Link to post
Share on other sites
I have one infinite loop, shown below

while(TRUE)
{
DWORD start_time = GetTickCount();
//look for a message
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//there is a message

//check that we arent quitting
if(msg.message==WM_QUIT) break;

//translate message
TranslateMessage(&msg);

//dispatch message
DispatchMessage(&msg);
}

//run main game loop
GameLoop();
while((GetTickCount() - start_time) < GAMESPEED)
{
}
}

Share this post


Link to post
Share on other sites
quote:
Original post by Kojo
I have one infinite loop, shown below

while(TRUE)
{
DWORD start_time = GetTickCount();
//look for a message
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//there is a message

//check that we arent quitting
if(msg.message==WM_QUIT) break;

//translate message
TranslateMessage(&msg);

//dispatch message
DispatchMessage(&msg);
}

//run main game loop
GameLoop();
while((GetTickCount() - start_time) < GAMESPEED)
{
}
}



When that break is hit the while containing PeekMessage() is left but NOT the one with the condition TRUE.


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
Try a variable to stop the loop when needed
a = true
while a
{
DWORD start_time = GetTickCount();
//look for a message
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE) || a)
{
//there is a message

//check that we arent quitting
if(msg.message==WM_QUIT) a = false;

//translate message
TranslateMessage(&msg);

//dispatch message
DispatchMessage(&msg);
}

//run main game loop
GameLoop();
while((GetTickCount() - start_time) < GAMESPEED)
{
}
}

(i only use C++ for console apps, And i'm not that good at it, but from what i know this should work).
edit: Forgot message

[edited by - Nice coder on May 20, 2004 4:07:22 AM]

Share this post


Link to post
Share on other sites
A break statement would be cleaner than adding the extra variable, a.


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
If there''s no code to execute after the outer loop then you coud replace the break with an exit(0) instead.

Share this post


Link to post
Share on other sites
Just change the "while(PeekMessage...) " to an "if(PeekMessage...)" and leave the "break;" where it is. Then you''re good to go.

Share this post


Link to post
Share on other sites
Thank you all very much for your responses. I added an extra break and the code works fine now.

It now looks like this...

while(TRUE)
{
DWORD start_time = GetTickCount();
//look for a message
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//there is a message

//check that we arent quitting
if(msg.message==WM_QUIT) break;

//translate message
TranslateMessage(&msg);

//dispatch message
DispatchMessage(&msg);
}

if(msg.message==WM_QUIT) break; // break from the infinite loop
//run main game loop
GameLoop();
while((GetTickCount() - start_time) < GAMESPEED)
{
}
}


I have another question and don't want to take up space with another new post... How do I get rid of text displayed by TextOut? If I try to fill a rect with black over some white text, nothing happens to the text... anyone?

EDIT: I've yet to make a post which I did not edit imeadiatly after I posted it...

[edited by - Kojo on May 20, 2004 9:16:23 PM]

Share this post


Link to post
Share on other sites
In what part of your code are you drawing this rectangle? Can you post the function that draws the rectangle over the text?


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
This covers the entire screen, but it should cover the text also...


RECT tab;
SetRect(&tab,0,0,MAPWIDTH,MAPHEIGHT+TAB);
FillRect(bmoMap,&tab,(HBRUSH)GetStockObject(BLACK_BRUSH));

Share this post


Link to post
Share on other sites
What is the datatype of bmoMap? HDC, yes? If so, can you post the code that you use to draw your text? If no then you need to select that bitmap into an HDC and call FillRect() on that HDC.


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
The text code is...


void DisplayScore()
{
HDC hdc = GetDC(hWndMain);
char text[20];

DrawTile(MAPWIDTH-25,MAPHEIGHT+(TAB/2), 5);
SetTextColor(hdc,RGB(255,255,255));
SetBkColor(hdc,RGB(0,0,0));

sprintf(text, "Score = %d", score);
TextOut(hdc,0,MAPHEIGHT+(TAB/2),text,strlen(text));

sprintf(text, "Balls = %d", ballsleft);
TextOut(hdc,120,MAPHEIGHT+(TAB/2),text,strlen(text));

sprintf(text,"%d",paddle);
TextOut(hdc,200,MAPHEIGHT+(TAB/2),text,strlen(text));

}


I just realized that I draw the text to hWndMain, but I fill the rect that is bmoMap. bmoMap shares the same amount of space but I''m assuming that would be the problem... (should probably go back and properly learn DC stuff ...)

Share this post


Link to post
Share on other sites
hey there...
i have some same problem...
when i close my program...sometimes there still a process called sapiserv.exe or sth like that...the computer turns slow...and i end this process manually...
whats the problem...
i''m using ms vc++ 6 under windows xp

--------------------
Ad Astra Per Aspera
--------------------

Share this post


Link to post
Share on other sites
As for the process staying bug, I had this exact same problem this morning. I asked on IRC and I got the solution. In your WndProc, when you receive the message to quit, you do ExitProcess(0);

Ex:

case WM_CLOSE:
{
KillWindow();
PostQuitMessage(0);
ExitProcess(0);
break;
}


This will close the process which is taking most cpu time in the task manager.

Share this post


Link to post
Share on other sites