function looping in windows

Started by
11 comments, last by Falken42 17 years, 11 months ago
How do I make a function constantly loop while a windows program is running without ignoring the windows message loop?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Advertisement
threads
Don't forget to craft a means to break the loop.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
is there a way besides threads?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
You could poll using PeekMessage, instead of using GetMessage which blocks. If a message exists, then Translate and Dispatch it.

No threads required.
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.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Then something in your SendRcv() function is blocking.
Then I guess this method won't work for me... all that's in that function right now is a recvfrom() function.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
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.
Couldn't I just use OnIdle()?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)

This topic is closed to new replies.

Advertisement