You want to process something whenever wxWidgets is not processing any events of it's own, (when using Win32 code, this would be like using PeekMessage), but you're not sure how to change the MainLoop in wxWidgets.
The Solution
After numerous attempts to solve this and an evening of reading, I finally have a solution that works; this solution has been tested using wxWidgets 2.8.8 with Visual Studio 2008 on Windows XP.
The solution works by using wxWidgets' event system to call a function whenever wxWidgets is idle (so no MainLoop changes required). To start with, you will need a class derived from wxApp (chances are you have this already by I will include a cut down version of my header for clarity):
Code: Select all
class CApplication : public wxApp
{
/* ... */
public:
void DoUpdate(wxIdleEvent &event);
/* ... */
DECLARE_EVENT_TABLE()
};
Now, in the CPP file for the above class, you will need to add some more macros to finish setting up the event table to call your "DoUpdate" function:
Code: Select all
BEGIN_EVENT_TABLE(CApplication, wxApp)
EVT_IDLE(CApplication::DoUpdate)
END_EVENT_TABLE()
Code: Select all
void CApplication::DoUpdate(wxIdleEvent &event)
{
/* ... */
if(IsMainLoopRunning())
event.RequestMore();
}
Notes
I hope this helps someone, I have seen many forum posts on this subject either unanswered or totally misinterpreted so I'm pretty sure this will help someone. Finally, I make no assumptions that this is the best solution, I have only been using wxWidgets for under a day myself and was looking for something with the relative simplicity of PeekMessage while avoiding threads.
Good luck.