[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Up: Examples Previous: Tcl/Tk

Motif

/* A SAMPLE Motif APPLICATION USING C
 * The online help system contains a motif tutorial.
 * This program creates a window with a button labelled `PushMe'. 
 * The program shuts down when the button's clicked on.
 *     c89 -I/usr/include/X11R5 -I/usr/include/Motif1.2
 *         -L/usr/lib/X11R5     -L/usr/lib/Motif1.2 -o demo demo.c 
 *     -lXm -lXt -lX11
 */

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/BulletinB.h>

  void quit()
  {
     printf("exiting now\n");
     exit(0);
  }

  main(argc,argv)
    int argc; 
    char *argv[];
  {
    Widget toplevel, bb, button2;
    Arg al[10];
    int ac;

    toplevel=XtInitialize(argv[0],"",NULL,0,&argc,argv);

    /* Size the main window */
    ac=0;
    XtSetArg(al[ac],XmNheight,200); ac++;
    XtSetArg(al[ac],XmNwidth,200); ac++;
    XtSetValues(toplevel,al,ac);

    /* create a bulletin board widget */    
    bb=XtCreateManagedWidget("bb",xmBulletinBoardWidgetClass,
          toplevel,al,ac);

    /* create a button */
    ac=0;
    XtSetArg(al[ac],XmNheight,30); ac++;
    XtSetArg(al[ac],XmNwidth,90); ac++;
    XtSetArg(al[ac],XmNx,90); ac++;
    XtSetArg(al[ac],XmNy,90); ac++;
    XtSetArg(al[ac],XmNlabelString,
          XmStringCreate("Push Me",
          XmSTRING_DEFAULT_CHARSET)); ac++;

    button2=XtCreateManagedWidget("button2",xmPushButtonWidgetClass,
          bb,al,ac);

    /* call the quit routine when the button is clicked on */

    XtAddCallback(button2,XmNactivateCallback,quit,NULL);
    XtRealizeWidget(toplevel);
    XtMainLoop();
  }


Tim Love
2001-07-26