The redraw function of a window General rules Non proportional window
Programming guideline of WinDom

proportional window

In this example, we want to open a window which containts a circle. In this case, sliders are not used. The data concerning this window is stored in a user structure and attached to the window. This provides us with some usefull informations about the window content (color, pattern, ...).

     struct circle {
          int color;
          int pattern;
     };
And now, the function in charge of destroying the window:

	void Destroy( WINDOW *win) {
		struct circle *C;

		C = (struct circle *) DataSearch( win, 'CIRC');
		free( C);                /* free memory */
		DataDelete( win, 'CIRC');
		WindClose( win);         /* close the window */
		WindDelete( win):        /* delete the window */
	}
The redraw function:

	void Draw( WINDOW *win) {
    	int x, y, w, h;
		struct circle *circ;

		circ = (struct circle *) DataSearch( win, 'CIRC');
		/* Get the workspace coordinates */
		WindGet( win, WF_WORKXYWH, &x, &y, &w, &h);
		/* Clear the background */
		WindClear( win);
		vsf_color( win->graf.handle, circ->couleur);
		vsf_interior( win->graf.handle, circ->motif);
		v_circle( win->graf.handle, x+w/2-1, y+h/2-1, min( w, h)/3);
	}
The main function is:

#define WIN_CIRCLE	1

	int main( void) {
		WINDOW *win;
		struct circle *C;

		/* Init WinDom */
		ApplInit();

		/* Create a circle data */
		C = (struct circle *) malloc( sizeof( struct circle));

		/* Create the window */
		win = WindCreate( WAT_ALL, app.x, app.y, app.w, app.h);

		/* Attach data to window */
		DataAttach( win, 'CIRC', C);
		win->type = WIN_CIRCLE;

		/* Declare new event message */
		EvntAttach( win, WM_REDRAW, Draw);
		EvntAttach( win, WM_DESTROY, Destroy);

		/* Open the window */
		WindOpen( win, app.x, app.y, app.w/2, app.h/2);
		WindSet( win, WF_NAME, "titre");
		WindSet( win, WF_INFO, "infos");

		/* Handle GEM event */
		while( wgbl.first)
			evnt_windows( MU_MESAG);

		ApplExit();
		return 0;
     }
To create a new kind of window we needed to:

This is the general way to create new window in a WinDom application. Note that the field type of the window descriptor is not used. It is just used to identify the nature of data attached to the window. In our case, the window is of type WIN_CIRCLE. Data are attached to the window using the function DataAttach(). Then data are recovered (for example, in the redraw function) using the function DataSearch().

To declare a new event function, we use the function EvntAttach(). It is a very important function in WinDom. Thus the call:

	      EvntAttach( win, WM_REDRAW, Draw);
give to the window win and the message WM_REDRAW the function Draw().

Try to compile this example and see how it works. If you close the window, the application exits. This example doesn't use any slider but in the next one, we are going to see how to handle them.