Home > Articles > Programming > User Interface (UI)

Programming C++ GUIs with the wxWidgets Library

  • Print
  • + Share This
The open source wxWidgets library makes programming GUIs incredibly easy, far easier than with most platform APIs. Jeff Cogswell shows how this handy C++ library can shorten your programming time with powerful classes that are simple to use.
Like this article? We recommend

When I set out to develop a program in C++, one of the hardest parts is figuring out what tools I’ll use to create the user interface. Since the language standard itself doesn’t provide any GUI classes, it’s up to the development tools to help me out here. I have lots of choices at my disposal; I can write code that calls into the Windows API (no, thank you—I did more than my share of that 10 years ago); or I can make use of a class library. Further, I can use a development tool that allows me to draw my windows graphically, or I can code them myself.

After years of creating programs on windowing systems such as Microsoft Windows and the Macintosh, I’ve come to realize that tools that let me draw a window onscreen barely help. The timesaving is minimal. Plus, the tool itself usually injects various codes into my source, and I’m not supposed to touch the codes. Or such tools maintain a separate file describing the GUI, and I’m not supposed to touch that separate file. Thus, as much as I enjoy using other languages such as C# and Visual Basic .NET, I find the designer portions of little value; I use the designers for some basic stuff, but the rest is all coding.

What’s more important to me is a good, strong class library. That’s where a library such as wxWidgets comes in.

Introducing wxWidgets

In a nutshell, wxWidgets is a library of C++ classes that do the following:

  • Simplify creating a GUI for your application
  • Provide more than just GUI classes (they include container classes, socket classes, and several other categories)
  • Allow for cross-platform development, whereby you can recompile your source for other platforms

And best of all, wxWidgets is free! It’s an open source tool and free for us to use, and it works on many different platforms, including Windows, Mac OS X, GTK+, X11, Motif, and even Windows CE and Palm OS.

Before getting into the nitty-gritty, I want to show you the categories of classes the library provides, so you can see how broad and useful it is:

  • Windowing (managed and miscellaneous)
  • Window layout (particularly important for cross-platform development)
  • Controls and menus
  • Common dialogs
  • Device contexts
  • Graphics
  • Events
  • Validation
  • Data structures (arrays, maps, points, rectangles, strings, and others)
  • Runtime type information
  • Logging and debugging
  • Networking (including sockets and various protocols such as HTTP and FTP)
  • Interprocess communications and threading
  • Document/View framework (if you want to use it)
  • Printing (always a headache in Microsoft Windows), which even includes print preview
  • Drag-and-drop
  • Files and streams (including various stream classes that are as easy to use as the ones Java programmers were blessed with years ago)
  • HTML
  • Virtual file system
  • XML
  • Online help (for the software you’re developing)
  • Databases
  • Miscellaneous, including such classes as wxCmdLineParser, wxSystemOptions, wxSingleInstanceChecker, and wxGLCanvas (for OpenGL) and more

Now, certainly, I won’t be able to cover all these categories in this single article, considering that each has multiple classes—many have two or three dozen classes. But I can show you some of the highlights. First, however, I want to talk about my experiences with installing the library.

  • + Share This
  • 🔖 Save To Your Account