Classes: wxEvtHandler, wxWindow
To handle events that are generated by the windowing system (usually in response to a user's action), the programmer must derive a class from the window that is sent the event, and define appropriate behaviour. For example, to respond to OnPaint messages from a wxCanvas, you would derive a new class MyCanvas and define the function MyCanvas::OnPaint. Within this function, you paint the canvas as necessary for your application.
To respond to a user closing a window, define OnClose; to intercept character input from a canvas, define OnChar, and so on. These events are listed in the class description for wxEvtHandler, which is the base class for all window classes.
In fact, you don't have to derive a new class from a window class if you don't want to. You can derive a new class from wxEvtHandler instead, overriding the appropriate member function, and then call wxWindow::SetEventHandler to make this event handler the object that responds to events. This way, you can avoid a lot of class derivation, and use the same event handler object to handle events from instances of different classes. If you ever have to call a window's event handler manually, use the GetEventHandler function to retrieve the window's event handler and use that to call the member function. By default, GetEventHandler returns a pointer to the window itself unless an application has redirected event handling using SetEventHandler.
You could use this technique to respond to panel item commands. Normally, you supply a function of type wxFunction to the panel item constructor, and it will be called with references to the panel item and command event. Instead, you could use a single wxEvtHandler object for handling one or more panel items, setting the event handler object for the panel item just after item construction. This handler could even be the panel or dialog box.
Another use of SetEventHandler is to temporarily or permanently change the behaviour of the GUI. For example, you might want to invoke a dialog editor in your application that changes aspects of dialog boxes. You can grab all the input for an existing dialog box, and edit it 'in situ', before restoring its behaviour to normal. So even if the application has derived new classes to customize behaviour, your utility can indulge in a spot of body-snatching. It could be a useful technique for on-line tutorials, too, where you take a user through a serious of steps and don't want them to diverge from the lesson. Here, you can examine the events coming from buttons and windows, and if acceptable, pass them through to the original event handler. Use Set/GetNextHandler and Set/GetPreviousHandler to form a chain of event handlers, taking care to pass events along the chain.