Jump to content
  • Advertisement
Sign in to follow this  
etsuja

function looping in windows

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

How do I make a function constantly loop while a windows program is running without ignoring the windows message loop?

Share this post


Link to post
Share on other sites
Advertisement
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
Then I guess this method won't work for me... all that's in that function right now is a recvfrom() function.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!