Thoughts on message loop processing caused by MessageBox Modal Dialog Box not blocking

Source: Internet
Author: User

At work, I suddenly found that MessageBox could not interrupt the message loops of timer and wm_hotkey, which made me very surprised. I thought about the message loop. Is it true that the message loop is still multi-threaded (absolutely impossible)? If not, why can I skip MessageBox and execute the next timer and wm_hotkey events? Is there any special processing? I went to review the books and materials to find out whether there is any special processing method, the result shows that only the timer event has a very low priority, which is rather modest. Nothing! Then I went online to query the information to see if there was anything special about timer, but there was still no result. Finally, I debugged it in the program and found a strange phenomenon. The Code is as follows:

While (getmessage (& MSG, null, 0, 0 ))

{
       Dispatchmessage (& MSG); ------------------------> event processing process {MessageBox (hwnd, "1 )}

       MessageBox (hwnd, "2", 0, 0 );
 }

 

 

Then run and find a magical phenomenon. In sequence, the mssagebox is displayed, and each time cancel is dropped, it is selected in order of 12. If it is not set to 1, 2 will not be selected, but 1 will continue to be selected in the future, if cancel is removed from the followed 2, 1, it is not selected, but if cancel is removed from the first stuck MessageBox, then it can jump out of 2. Suddenly, I came up with some inspiration. It seems that MessageBox is still stuck in the message loop, so 1 is not cancel2, messagebox1 will pop out later because we ignore MessageBox and have our own message loop to receive timer messages. parse the above Code as follows:

While (getmessage (& MSG, null, 0, 0 ))

{

       
.........
       

While (getmessage (& MSG, null, 0, 0 ))

{
       Dispatchmessage (& MSG );
 }

.........

 }

The red is the mssagebox in the message processing process. Therefore, when bossageboxblock is used, timer and wm_hotkey messages can still be received.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.