c - Is there a difference between using `PostQuitMessage` and just processing all messages? -


I wonder if there is a difference between those snippets:

one:
  void main () {// ... while (GetMessage (& msg, NULL, 0, 0)) {translationMessage (& msg); DispatchMessage (& amp; msg); } Exit Process (0); } // ... leaving zero () {PostQuitMessage (0); }   

two:
  bool quit = false; Zero main () {// ... while (GetMessage (& msg, NULL, 0, 0)) {TranslateMessage (& amp; msg); DispatchMessage (& amp; msg); If (left) {while (peakmasase (& msg, NULL, 0, 0, PMIMOV)) {translateMessage (& amp; msg); DispatchMessage (& amp; _msg); } Exit Process (0); }} // should not quit here. Process (1); } // ... leave zero () {quit = true; PostTrust Message (GetCurrentThreadId (), WM_NULL, 0, 0); }   

Sorry, but I can not come up with small snippets.

The issue of my question is that to call PostQuitMessage and process everybody with GetMessage with the message PeekMessage This is equivalent to processing all messages, as long as it FALSE .

, WM_QUIT returns "only when the message queue is otherwise empty", it seems that two methods should do this, but there is probably a subtle difference.

Because the system tries to not inject a WM_QUIT message to "bad time"; Instead, it waits for things before creating a WM_QUIT message, which reduces the probability that this program is in the middle of the multi-level process triggered by the sequence of post messages.

So in theory number, there is no difference, because the system will not generate WM_QUIT until Q is empty. Although Raymond does not say that it is the guarantee is that the message will not come after the generated WM_QUIT , only that the system tries to escape from.

So it is possible that when you exit your main GetMessage loop, another thread can send you a message, and depending on your application, There may be something for me. For example, if you post messages internally with memory allocation, the receiving thread is likely to be free, you may need a separate PeekMessage loop, from First of all, that yarn should be completely removed.

In practice, however no one ever writes a message loop like your second example.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -