Sign in to follow this  

function looping in windows

This topic is 4226 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

You could poll using PeekMessage, instead of using GetMessage which blocks. If a message exists, then Translate and Dispatch it.

No threads required.

Share this post


Link to post
Share on other sites
I'm trying to do this and it's not working


do
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);

}

SendRcv();
}
while(TRUE);




doesn't seem to be accepting any messages. I can't click any menu items.

Share this post


Link to post
Share on other sites
Windows Sockets are set to default to blocking unless you explicitly disable blocking with ioctlsocket and the FIONBIO argument. You'll have to then properly handle the WSAEWOULDBLOCK return value from recvfrom.

Writing code which polls everything (sockets, messages, objects, etc) is a lot harder to manage. Putting your network code on a separate thread while keeping the message pump in blocking mode on the main thread would probably be the most ideal situation.

Share this post


Link to post
Share on other sites
Sure, if you're using MFC.

But you can't have any blocking calls within OnIdle. And OnIdle is only called when the application's message queue is empty.

Share this post


Link to post
Share on other sites
K, well I guess I'm gonna be forced to use threads, I've never used them before though so I have another question that I don't see answered on msdn. how do you check to see if a thread is running?

EDIT:nevermind, I was gonna use the loop previously mentioned and create a new thread, check to see if it was running and if not destroy it every iteration but now I'm just creating a thread at initialisation that runs a constantly looped function. I just hope I can get away with running unsychronized threads.

[Edited by - etsuja on May 22, 2006 11:23:05 PM]

Share this post


Link to post
Share on other sites

This topic is 4226 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this