GlockenspielCommonView Tutorial | |
The Event Handler |
|
Glockenspiel CommonView was "a C++ application framework" for Windows and OS/2. CommonView came out around Windows 1.1 when the only way to program Windows was with the Microsoft SDK. Essentially, it was the precursor to Microsoft's Foundation Class Library (some of Glockenspiel's developers went to Seattle to lead this effort). At the time few knew how to program for Windows (there was only one decent book available: the seminal "Programming for Windows" by Charles Petzold). I had less than four months to figure out how to program in C++ (so I could update the compiler manual), learn the basics of Windows programming, figure out how CommonView made it easier and then write the tutorial. The hardest part, oddly, was understanding the concept of the CommonView Event Handler, a virtual function that developers would have to modify themselves. So simple now, but I was sweating buckets at night until I suddenly 'got it'. I'd probably write a better version today but the following is what ended up in the tutorial. Event Handling
This chapter discusses how CommonView handles actions taking place in the GUI - such as invoking menus, scrolling windows, moving the mouse, closing an application and so forth.
What is an Event?
The CommonView window environment is event-driven: the user directs the flow of the program by choosing menus, entering text and clicking various options. When something happens (an event) - such as a mouse click - the windowing system must determine what caused it and which window it occurred in.
The program must determine what action to take in response to the event, in other words, how to handle the event. This involves developing a range of functions to cope with actions such as selecting menu options, clicking on controls like RadioButtons, pressing the keyboard or entering text. Each event, therefore, has an associated 'event handler'.
When an event occurs, CommonView calls the associated event handler. For example, the function Menu Command() is invoked when the user chooses an item on a menu. (This function typically analyses which option has been chosen and processes it accordingly).
Writing an Event Handler
CommonView's Event Handlers are provided as virtual functions in the Window class. Since they're virtual functions, it means you can write your own specific behaviour for them.
For example, the Close() event handler is called when a window is being closed. You
could redefine Close() so 'tidying up' code is executed before closing the application - such as closing down files.
You do not need to introduce extra code to invoke the tailored event handler - CommonView and C++ automatically take care of that. If you don't tailor the function, CommonView calls its default event handler whenever an event is generated.
Note: The default implementation of event handlers are part of CommonView's dynalink library and are automatically brought in at the linking stage. CommonView requires the Exec() function to be called to set off this event handling mechanism - Chapter 6: "Opening a Window" demonstrates how this is done.
Arguments to Event Handlers
The arguments passed to each event handler are the object representations of the event, based on CommonView classes. In effect they contain the crucial information concerning the nature of the event - the Who, What, Where and When aspects. Although this data is private, the event object's member functions provide the necessary access so you can obtain their values.
|
© 2001 John Rowley - All rights reserved. |