Something like what you describe could be done by coroutines. But here,
with modal dialogs the things are simpler, it's just a recursive call to
some kind of PumpMessage loop. In Windows all events are placed in the
window event queue, there are functions for processing them, typically
called something like PumpMessage, and when processing some event, the
handler code can contain a new message loop which will process all the
messages by itself for a while.
Here is a call stack from an event handler inside a modal dialog, with
many frames omitted for brevity. This is from MFC, not wxWidgets, but
they should be similar enough here.
Note how e.g. CWinThread::PumpMessage() appears twice in the call stack,
meaning that it is called recursively.
The first event processing loop is apparently in CWinThread::Run() in
the bottom of the stack, and the second one is in CWnd::RunModalLoop().
[....]
mfc140ud.dll!AfxPreTranslateMessage(tagMSG * pMsg) Line 252 C++
mfc140ud.dll!AfxInternalPumpMessage() Line 178 C++
mfc140ud.dll!CWinThread::PumpMessage() Line 900 C++
mfc140ud.dll!AfxPumpMessage() Line 190 C++
> mfc140ud.dll!CWnd::RunModalLoop(unsigned long dwFlags) Line 4661 C++
mfc140ud.dll!CWnd::CreateRunDlgIndirect(const DLGTEMPLATE *
lpDialogTemplate, CWnd * pParentWnd, HINSTANCE__ * hInst) Line 485 C++
mfc140ud.dll!CDialog::DoModal() Line 652 C++
[..........]
mfc140ud.dll!CWnd::IsDialogMessageW(tagMSG * lpMsg) Line 194 C++
mfc140ud.dll!CWnd::PreTranslateInput(tagMSG * lpMsg) Line 4607 C++
mfc140ud.dll!CControlBar::PreTranslateMessage(tagMSG * pMsg) Line 440 C++
mfc140ud.dll!CControlBar::PreTranslateMessage(tagMSG * pMsg) Line 431 C++
mfc140ud.dll!CWnd::WalkPreTranslateTree(HWND__ * hWndStop, tagMSG *
pMsg) Line 3379 C++
mfc140ud.dll!AfxInternalPreTranslateMessage(tagMSG * pMsg) Line 233 C++
mfc140ud.dll!CWinThread::PreTranslateMessage(tagMSG * pMsg) Line 778 C++
mfc140ud.dll!AfxPreTranslateMessage(tagMSG * pMsg) Line 252 C++
mfc140ud.dll!AfxInternalPumpMessage() Line 178 C++
mfc140ud.dll!CWinThread::PumpMessage() Line 900 C++
mfc140ud.dll!CWinThread::Run() Line 629 C++
mfc140ud.dll!CWinApp::Run() Line 787 C++
EvoShellD.exe!CShellApp::Run() Line 1051 C++
mfc140ud.dll!AfxWinMain(HINSTANCE__ * hInstance, HINSTANCE__ *
hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 47 C++
EvoShellD.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ *
hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 26 C++
EvoShellD.exe!invoke_main() Line 123 C++
EvoShellD.exe!__scrt_common_main_seh() Line 288 C++
EvoShellD.exe!__scrt_common_main() Line 331 C++
EvoShellD.exe!wWinMainCRTStartup(void * __formal) Line 17 C++
kernel32.dll!00007ffc7f5e74b4() Unknown
ntdll.dll!00007ffc815026a1() Unknown