Event driven programming

In classical programming, we are in control of the control flow.

In GUI programming the user is.

So what do we do? We would need to do something like this (this is not actual code!):

while (true) {
  event = waitForUserToClickSomething();

and this is acutally the way it is done in classical GUI programming. But we are thinking in terms of classes and objects, and messages between these objects.

So when the user clicks somethings, we want a message to be sent to some object.

We need to tell the computer what event should be sent to which object.

This is the purpose of the event table. It describes which methods should be called on which event.

The EVENT macros implement this behavior for us.

It can also be done programmatically (see wxWidgets documentation).

Inside your declaration, use this:


Inside your implementation file, use something like this:

    EVT_MENU(ID_Quit, MyFrame::OnQuit)
    EVT_MENU(ID_About, MyFrame::OnAbout)

This will implement an event handler for the class "MyFrame" which is subclassed from "wxFrame". For the menu event with the id "ID_Quit" it will call the method "OnQuit" from "MyFrame". For the menu event with the id "ID_About" it will call the method "OnAbout".

Prefixing event methods with "On" is just a convention and not required. But it is a good idea.