S
Aus dem wxWidgetsSample mediaplayer, Datei: mediaplayer.cpp, Ab Zeile 550, wxWidgets 2.8.10
//
// Connect events.
//
// There are two ways in wxWidgets to use events -
// Message Maps and Connections.
//
// Message Maps are implemented by putting
// DECLARE_MESSAGE_MAP in your wxEvtHandler-derived
// class you want to use for events, such as wxMediaPlayerFrame.
//
// Then after your class declaration you put
// BEGIN_EVENT_TABLE(wxMediaPlayerFrame, wxFrame)
// EVT_XXX(XXX)...
// END_EVENT_TABLE()
//
// Where wxMediaPlayerFrame is the class with the DECLARE_MESSAGE_MAP
// in it. EVT_XXX(XXX) are each of your handlers, such
// as EVT_MENU for menu events and the XXX inside
// is the parameters to the event macro - in the case
// of EVT_MENU the menu id and then the function to call.
//
// However, with wxEvtHandler::Connect you can avoid a
// global message map for your class and those annoying
// macros. You can also change the context in which
// the call the handler (more later).
//
// The downside is that due to the limitation that
// wxWidgets doesn't use templates in certain areas,
// You have to triple-cast the event function.
//
// There are five parameters to wxEvtHandler::Connect -
//
// The first is the id of the instance whose events
// you want to handle - i.e. a menu id for menus,
// a control id for controls (wxControl::GetId())
// and so on.
//
// The second is the event id. This is the same
// as the message maps (EVT_MENU) except prefixed
// with "wx" (wxEVT_MENU).
//
// The third is the function handler for the event -
// You need to cast it to the specific event handler
// type, then to a wxEventFunction, then to a
// wxObjectEventFunction - I.E.
// (wxObjectEventFunction)(wxEventFunction)
// (wxCommandEventFunction) &wxMediaPlayerFrame::MyHandler
//
// Or, you can use the new (2.5.5+) event handler
// conversion macros - for instance the above could
// be done as
// wxCommandEventHandler(wxMediaPlayerFrame::MyHandler)
// pretty simple, eh?
//
// The fourth is an optional userdata param -
// this is of historical relevance only and is
// there only for backwards compatibility.
//
// The fifth is the context in which to call the
// handler - by default (this param is optional)
// this. For example in your event handler
// if you were to call "this->MyFunc()"
// it would literally do this->MyFunc. However,
// if you were to pass myHandler as the fifth
// parameter, for instance, you would _really_
// be calling myHandler->MyFunc, even though
// the compiler doesn't really know it.
//