John Torjo - C++ Expert

eGUI++ - Easy GUI

What's eGUI? It's a C++ library that makes Windows GUI programming a breeze!

Yup, it's finally here, and it's hot!

Download it


eGUI's goals

  • make GUI code easy to read
  • make GUI code easy to write
  • benefit from code completion whenever possible
  • make GUI programming safe 
    • in case there’s an error, catch it at compile time whenever possible; otherwise, at runtime, an exception is thrown
  • Resource Editor friendly
    • Integration with VS 2005+ Resource Editor
  • no message maps
  • No need to #include <windows.h> in client code. This was quite bold, but I've made it. You want a library that abstracts away the Win32 API FULLY, here it is.

Case in point : USD to EUR conversion

You'll find the sample in samples/tutorial/usd_to_eur.

To deal with the GUI world, you create forms (or dialogs, if you wish). Then you put controls on them, and the handle some of their events to implement the logic.

Step 1: The main() function

using namespace egui;
void egui::main(const main_args&) {
    // create a modal form. You don't need to specifically wait for an event from the modal form,
    // since you'll exit this function only when it's ready
    wnd<convert>( new_( wnd_init().style(form_style::modal) ));

Step 2: The convert class

The convert class - it's the form that does the conversion. It's fairly simple
The header:

// convert.h
#include "convert_form_resource.h"
struct convert :   form_resource::convert {
    convert() : rate(1.47), updating(false) {}
    double rate;
    bool updating;

    // here we specified what notifications we're handling:
    // the "change" event, coming from usd, and from eur controls
    void on_change(edit::ev::change&, usd_);
    void on_change(edit::ev::change&, eur_);

The source code:

// convert.cpp
#include "stdafx.h"
#include "convert.h"
#include "convert_form_resource.h.hpp"
namespace {
    double to_double(const string& str) { ... }
    string to_string(double d) { ... }

// handle each event, and update the other control
// also, avoid infinite recursion
void convert::on_change(edit::ev::change&, usd_) {
    if ( updating) return;
    updating = true;
    eur->text = to_string( to_double(usd->text) / rate);
    updating = false;
void convert::on_change(edit::ev::change&, eur_) {
    if ( updating) return;
    updating = true;
    usd->text = to_string( to_double(eur->text) * rate);
    updating = false;