Information for Programming

with wxWidgets

 

bullet Style of Programming:  The programming style when creating a program with a graphical user interface (GUI) is quite different than console (or text-based) programs like those which use cin and cout for input and output.  Console-style programs typically use a call-and-return architecture (i.e., a main program with calls to functions) as shown in the diagram below on the left.  GUI-based programs typically use an event-driven, callback architecture, where the system classes contain the main() program with its event loop and the interface (embodied in the GUI class) is constructed at initialization from a template application class.  That application class is often inherited from the a class in the GUI library which has the proper method calls for initialization and termination of the application.  The GUI class, once initialized registers event handlers which afterwards respond to the user-generated events, as demonstrated in the diagram below on the right.


 



 
         

 

 

 

 

 

bullet Resources:  To develop a GUI-based application, you need a set of graphical controls (or widgets as they are often called) such as buttons, check boxes, scrollbars, text fields, menus, etc.  You could write these controls yourself using C++ or some other programming language, but generally you will use a GUI toolkit (or library) that someone has already written for that purpose.  Common toolkits are Microsoft Foundation Classes (MFC), Motif, Tcl, AWT, Swing, Qt, or wxWidgets.  Keep in mind that whatever toolkit you choose has to work your application programming language and operating system--these restrictions will limit your choices somewhat.  Most of the toolkits referenced above work on both linux and Windows, except MFC (Windows only) and Motif (linux traditionally).  Tcl, AWT and Swing are compatible with Java.  MFC, Motif, Tcl, Qt, and wxWidgets work with C++.

While not necessary, a helpful addition to a GUI toolkit, is a GUI builder application.  This app helps the programmer build user interfaces in a drag-an-drop or WYSIWYG fashion.  This kind of app can be an enormous help in productivity if you intend to build more than just a toy GUI, so such a tool is well worth the time you invest in learning how to use it.  With GUI programming being more pervasive than ever, it is getting common to see GUI development built into the programming environment.  As such, you can find GUI development capabilities in Visual Studio for C# and Visual Basic, NetBeans for Java, and several other Integrated Development Environmments (IDEs), both commercial and open source.

bullet GUI-Development Libraries:  In CS1220, we have chosen to introduce to you the wxWidgets toolkit.  We have selected wxWidgets, because it commonly -used, "industrial strength", freely available, well-supported, well-written, and compatible with C++ in both the Windows and linux O/Ss.

bullet GUI Building Applications:  Another positive for choosing wxWidgets is that there is a GUI builder application called wxFormBuilder that is compatible with wxWidgets, and well-integrated with Visual Studio.  wxFormBuilder allows us to take away some of the mystery of how to use the wxWidgets library to create the GUI for our application.  For more information on how to get started building an application with wxFormBuilder and wxWidgets, please see below.
 


bullet Getting Started:  Because most of the "action" in an event-driven program is done in response to user events (e.g., mouse clicks, key presses, scrollbar movement, etc.), it is common for the event handlers to comprise the bulk of the "application", that is, what the programmer writes to accomplish the task at hand.  When a a"GUI builder" application is provided (such as wxFormBuilder), this GUI builder automatically constructs the GUI class (in particular the GUI class constructor) and registers the appropriate event handlers for each of the widgets.

Since the GUI App Class is generally templated code (follow these links for examples files:  wxWidgetsApp.cpp and wxWidgetsApp.h) we can begin by copying such code into our project with limited modifications.  Next, we use wxFormBuilder to create the GUI Class with its associated event handlers.  Event handlers are created as stubs, so you (the programmer) will complete the event handlers as the final step.

However, before getting started with the event handlers, you should note how they are associated with the GUI Class, because the manner in which they are associated differs depending on the GUI builder tool.  Some tools, such as DialogBlocks, keep the event handlers in the GUI class and use an event table within the GUI class to bind the handlers to the events.  Other tools, such as wxFormBuilder, register the handler with the corresponding events using a connection method call.  Additionally, wxFormBuilder encourages the programmer to create a sub-class for the GUI class to override the GUI class event handlers.  This allows the programmer-specific code in the event handlers to be separated from the GUI class code which controls the application's appearance.