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.