How to find out if in a ShowModal event loop Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
richard_examion
Experienced Solver
Experienced Solver
Posts: 69
Joined: Wed Feb 27, 2019 7:17 am

How to find out if in a ShowModal event loop

Post by richard_examion »

Is there a robust way to find out if a process hangs in an event loop of a modal dialog.
I am testing a gui and sometimes a modal dialog blocks the progress of the testing code. If so, I would like to end the modal dialog and continue testing. Sofar I do this (in an wxIdleEvent) to achive what I´d like to do, but it seems not completely reliable:

Code: Select all

wxEventLoopBase *const activeLoop = wxEventLoop::GetActive ();
    if (!activeLoop->IsMain () && m_closeModalMessageBox)
    {
	int res = 0;
	activeLoop->ScheduleExit (res);
	m_closeModalMessageBox = false;
    }
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: How to find out if in a ShowModal event loop

Post by PB »

Did you try using wxModalDialogHook?

https://docs.wxwidgets.org/latest/class ... _hook.html

I find odd that wxEventLoopBase::IsMain() returns incorrect information. Perhaps this happens when the dialog is not an actual wxWidgets dialog but a wrapper around a native API (e.g., Common Dialogs on Windows)?
richard_examion
Experienced Solver
Experienced Solver
Posts: 69
Joined: Wed Feb 27, 2019 7:17 am

Re: How to find out if in a ShowModal event loop

Post by richard_examion »

Wow, that looks like what I need!
Thanks for the link!
richard_examion
Experienced Solver
Experienced Solver
Posts: 69
Joined: Wed Feb 27, 2019 7:17 am

Re: How to find out if in a ShowModal event loop

Post by richard_examion »

PB wrote: Wed Sep 28, 2022 7:21 am Did you try using wxModalDialogHook?

https://docs.wxwidgets.org/latest/class ... _hook.html

I find odd that wxEventLoopBase::IsMain() returns incorrect information. Perhaps this happens when the dialog is not an actual wxWidgets dialog but a wrapper around a native API (e.g., Common Dialogs on Windows)?
I think, it´s not so much about the IsMain() returns bad information, it is rather that I don´t get an IdleEvent when a wxMessageDialog is modal, hence I have no opportunity to ask for the loop to be main...
Post Reply