tags:

views:

60

answers:

2
A: 

You need a GetMessage loop from that article instead.

Kirill V. Lyadvinsky
+1  A: 

Well, that doesn't make any sense of course. If the fDone flag is set to TRUE, there's no way it can stay inside the loop and keep calling PeekMessage(). Nor can PeekMessage() block. Blowing the stack frame could have an effect like that, but that's not indicated here and always an explanation of last resort.

The more likely explanation is that this code gets repeatedly executed from the top. Maybe by you calling it from the window procedure. Yes, that can get you in an endless loop easily if you don't call DispatchMessage(). The WM_PAINT message is an obvious candidate, it will just keep firing without letup if you don't call Begin/EndPaint(). This is just a theory of course, can't know for sure without knowing how this code is getting called.

Hans Passant
yes it is called from the window procedure,So if I understood: every time I call PeekMessage() I have to call DispatchMessage()?but does not PeekMessage dispatch messages automatically?from MSDN: "Dispatches incoming sent messages"
Mario
Dispatches *sent* messages. Different from *posted* messages. WM_PAINT is posted, not sent. The example you're playing with is *not* a great one, nobody does this.
Hans Passant
ok thanks for replies, one last thing: why nobody does this? What is the alternative?
Mario
You use a thread.
Hans Passant