Example 1.1 of the tutorial : Create and handle a window

Create, open and handle a blank window in a GEM environment. More...

This is a very simple program. A single window is created and opened on screen.

 * WinDom: a high level GEM library
 * Copyright (c) 1997-2006 windom authors (see AUTHORS file)
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 * $Source: /cvsroot/windom/htdocs/doc/html/group__tut1__1.html,v $
 * CVS info:
 *   $Author: bercegeay $
 *   $Date: 2006/06/22 11:58:28 $
 *   $Revision: 1.5 $

Very important: you have to include windom.h header file.

#include <stdlib.h>
#include <windom.h>

You may have noticed than gemlib header in not here. It's ok because windom requieres gemlib as GEM library, and so windom.h internally includes gem.h and gemx.h. You don't have to include "gem.h" in your code.

int main( void) {
    /* window descriptor */
    WINDOW *win;
    /* WinDom initialisation */
    /* Create a window and keep its descriptor */
    win = WindCreate( NAME|MOVER|CLOSER, app.x, app.y, app.w, app.h);

In this example, user can manipulate the window (resizing, moving, topping, iconifying, ...). Windom has attached the standard callback function by default to the new created window, so that all event received by the application (resize of the window, window placed on the top, window iconified...) are "internally" treated by windom.

The standard callback function of WM_REDRAW event is mt_stdWindClear(). So, the work area of the window is always "cleared".

These standard callback functions are attached to the window by the function WindCreate().

    /* Open the window */
    WindOpen( win, app.x, app.y, app.x+app.w/2, app.y+app.h/2);

    /* Give it a title */
    WindSetStr( win, WF_NAME, __FILE__ ": Simple GEM window");

    /* Handle the GEM events */
    while( wglb.first) EvntWindom( MU_MESAG);

The main loop of any windom application should call EvntWindom(). In this function, windom will internally call the AES evnt_multi() to get informed of AES event for this application, and then EvntWindom() will dispatch the event to the right callback function.

This loop ended when the condition "wglb.first" is false. This is a pointer to the first window of the application managed by windom. When all the windows of this application are closed, then wglb.first is NULL and then, the while() loop is leaved.

In our example, when the user destroys the window. In fact, when you clic on the CLOSER widget, AES emits an WM_CLOSED message. The standard callback function std_cls() linked to this event acts by emitting an WM_DESTROY message and the destroy standard callback function std_dstry() acts by closing and deleting the window. In WinDom, we make the distinction beetween close a window and destroy a window. WM_DESTROY means that the window and its data have to be destroyed and WM_CLOSED means window is just closed but not deleted

From that point, wglb.first is set to NULL, and the while() loop is then leaved.

    FormAlert( 1, FA_INFO "[Program successfully terminated.][OK]");

    /* Terminate WinDom session */
    return EXIT_SUCCESS;

Probably, your first attempt is to define a custom window redraw callback and a custom destroy function, so go to Example 1.2 of the tutorial : Window drawing callback.

Generated on Thu Jun 22 11:45:28 2006 for WinDom by  doxygen 1.4.6