Adding wxEvtHandler to wxApp at runtime
Volker Bartheld
dr_versaeg at freenet.de
Wed Jul 4 08:41:25 PDT 2007
Hi!
Depending on some command line arguments, my application performs different
tasks. Some very basic events are handled at wxApp-level. I thought about
deriving two classes from wxEvtHandler
class Task1 : public wxEvtHandler;
class Task2 : public wxEvtHandler;
and adding either one or the other to the event handler chain of
class MyApp : public wxApp
at runtime using wxEvtHandler::SetNextHandler of MyApp but didn't have much
success so far. Is that a good way to solve the problem?
Another option would be to forward a selection of event types in MyApp to
either Task1 or Task2 using
DEFINE_EVENT_TYPE(EVT_TASK)
DECLARE_EVENT_TYPE(EVT_TASK, -1)
BEGIN_EVENT_TABLE(MyApp,wxApp)
EVT_COMMAND(wxID_ANY, EVT_TASK, MyApp::OnTaskEvent)
END_EVENT_TABLE()
MyApp::OnTaskEvent(wxCommandEvent &evt)
{
if(bTask1) m_Task1.AddPendingEvent(evt);
else m_Task2.AddPendingEvent(evt);
}
etc. but this seems a bit clumsy especially if there are many EVT_TASK-like
events.
Since only classes derived from wxWindow have wxWindow::PushEventHandler(),
I could also create a (hidden) main window, class TaskWin : public
wxWindow; in MyApp that gets Task1 or Task2 pushed in. Would that work?
Thanks in advance for some insights!
Volker
--
mailto: V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list