function looping in windows
How do I make a function constantly loop while a windows program is running without ignoring the windows message loop?
You could poll using PeekMessage, instead of using GetMessage which blocks. If a message exists, then Translate and Dispatch it.
No threads required.
No threads required.
I'm trying to do this and it's not working
doesn't seem to be accepting any messages. I can't click any menu items.
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.
Then I guess this method won't work for me... all that's in that function right now is a recvfrom() function.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement