As IInspectable explained, the modal dialog will run in the same thread as the caller. Therefore if you run the dialog from the main UI thread that has your main message loop, you'll end up with a nested message loop. The stack would look something like:
WinMain
YourMainMessageLoop
DispatchMessage
SomeMessageHandler
DoModal
and DoModal
spins in its own GetMessage
/TranslateMessage
/DispatchMessage
loop. The main message loop (YourMainMessageLoop
in the sample stack above) is "active" in the sense that it's still running, but it's blocked by the dialog's message loop. Execution won't return to YourMainMessageLoop
until DoModal
exits.
Note that even if you're within the modal dialog's message loop, your other windows will still handle messages because GetMessage
and DispatchMessage
will still retrieve and direct messages to those windows and invoke their WndProc
s.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…