Simple question about while (GetMessage (&messages, NULL, 0, 0)) loop

Jan 13, 2009 at 12:38am
I've been making a server program and inside the loop I have the server respond to messages from clients.
I've noticed that if the window is in focus it always answers instantaneously, but if the window is not in focus, it does not respond to the clients until it gains focus.
It would seem to me then, that background windows don't process messages until they get focus. Is this correct?
How can I avoid the issue so that my server responds immediately?
Last edited on Jan 13, 2009 at 12:38am
Jan 13, 2009 at 7:01pm
Have you looked at PeekMessage(); ?
Jan 15, 2009 at 11:40am
I'd never looked at it before, thanks ^.^

My main loop now looks something like this:
while(running)
{
if (PeekMessage( &messages, NULL, 0, 0, PM_REMOVE)!= 0)
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
packet = server->Receive();
if(packet != NULL)
{
HandlePacket(server, packet);
server->DeallocatePacket(packet);
}
for(int i = 0; i < PlayerList.size(); i++)
if(!server->IsActivePlayerID(PlayerList.at(i).ID))
PlayerList.erase(PlayerList.begin()+i);
}

Now I'd like to know if its bad practice to have a bool variable determining the loop of a windows program.
I have WM_CLOSE and WM_DESTROY change the value to false, is there any other condition where Windows would send a message to my program to quit and end up leaving it running still?
Last edited on Jan 15, 2009 at 11:40am
Jan 15, 2009 at 7:02pm
WM_QUIT? Have a look up to see what the PostQuitMessage() creates.

Jan 16, 2009 at 12:34am
Thanks, Zaita ^.^ you're always so helpful
Jan 16, 2009 at 12:35am
I have a OpenGL 3D engine @ home that I wrote. :P So I've been through all this stuff myself.
Jan 17, 2009 at 7:05am
learn
Topic archived. No new replies allowed.