GtkOL Reference Manual

1.4. GtkOL Hello World !

    The simpliest way and the more direct one to see how to deal with the GtkOL API is to see how to write a typical and well known "Hello World !" application.

    You could have two approaches to deal with the GtkOL API. The first one is to use the objects as they are provided. The second one is to derive the given widgets classes to set yours. Anyway, whatever the choice is, because the GTK+ library has to be initialized, a GtkOL application should always declare a CApplication instance that have to be the first instanciated GtkOL component and that will do so. Then you can add your specific widgets, typically, first of all, a form that will contain your application's GUI.

helloworld.png

    So, the GtkOL Hello World execution entry point would be something like that :

#include "capplication.h"

class CHelloButtonListener : public CButtonListener
{
   virtual void OnClick (CObject *)
   {
      ::fprintf (stdout, "Hello World\n");
   }
};

int main (int argc, char **argv)
{
   CApplication Application (argc, argv);
   
   CForm *aForm = new CForm (&Application);
   aForm -> SetPadding (10);

   CButton *aButton = new CButton (aForm, new CHelloButtonListener());
   aButton -> SetCaption (CString("Hello World"));

   aForm -> Show ();

   Application.Run ();

   return 0;
}


    It can be build with the following compilation directive :

c++ -Wno-multichar -O2 -o helloworld `pkg-config --cflags libgtkol-1.2` helloworld.c `pkg-config --libs libgtkol-1.2`