Home > Articles > Programming > User Interface (UI)

Programming C++ GUIs with the wxWidgets Library

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Cross-Platform GUI Programming with wxWidgets

Like this article? We recommend
Cross-Platform GUI Programming with wxWidgets

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.

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 ThisShare This
  • Your Account

Discussions

About memory leak tool
Posted Aug 23, 2007 01:12 AM by kallipudivk
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network