omtk - a platform independent GUI toolkit

omtk prorgramming tutorial


Note: This tutorial is very old and it's not finished.


  1. Getting started
  2. Menus
  3. Events

1. Getting started

Every omtk application starts with a omtk_main() function, which is similar to the C main() function:

#include <omtk.h>

int omtk_main(int argc, char *argv[])
  return 0;

You can compile this application as follows, where app.c is the filename of the source code and app is the name of the application:

omtk-compile app app.c
omtk-bundle app

The first command compiles and links the application. The second command is only important for MacOS X: It creates a bundle so you can launch the application from the Finder. If you are using the GTK2 port it does nothing.

You can also compile and link separately:

omtk-compile -c app.c
omtk-compile -l app app.c

It is possible to specify C flags and libraries:

CFLAGS=-Wall LIBS=-lyourlib omtk-compile app app.c

2. Menus

To create a widget, you have to declare an OmtkWidget structure and then call a function to allocate memory for it. So let's create a menu: First, create a menu which will store the menu items of the main menu (like File, Edit, etc.):

OmtkWidget *main_menu;

main_menu = omtk_menu_create();

Then create some menu items:

OmtkWidget *file_item, *edit_item;

file_item = omtk_menuitem_create("File");
edit_item = omtk_menuitem_create("Edit");

Append the items to the main menu:

omtk_menu_item_append(main_menu, file_item);
omtk_menu_item_append(main_menu, edit_item);

And don't forget to set the new menubar:


Now compile and run the application. You should see two empty menus, File and Edit. Let's create the submenus. Make sure you insert the following before the omtk_application_menubar_set() function:

OmtkWidget *file_menu, *file_new_item;

file_menu = omtk_menu_create();
file_new_item = omtik_menuitem_create("New");
omtk_menu_item_append(file_menu, file_new_item);

omtk_menuitem_submenu_set(file_item, file_menu);

After compiling you should have a menu item New in the menu File. See the demo application for details.

3. Events

You can add events with the omtk_event_add() function. You have to pass the widget as the first argument or NULL, if it's an application event. The second argument is the event type, the third is the function that should be called and the fourth can be NULL or a variable that will be passed to your function. Here's an example:

int exited(OmtkEvent *event, void *custom)
  printf("application should exit, %d\n", (int)custom);

  return 0;

int omtk_main(int argc, char *argv[])
  omtk_event_add(NULL, OMTK_EVENT_SHOULD_TERMINATE, exited, 123);
  return 0;

If you return 1 in the exited() function, then the event is marked as handled and the application won't terminate. You can find more events in the demo application.

Zurück zu | Back to

Last update: 20.02.04

Copyright (C) 2004, 2005 by Thomas "tom" Steinacher <tom at> Logo Valid HTML 4.0!