lemoncube.com Search: (normal)
Articles
Links
News
Projects

Disclaimer

Motif Example: Create simple dialog box

To compile this (lets say you call it motmess.c):

   gcc -I/usr/X11R6/include -L/usr/X11R6/lib -lXm -lXt -lX11 -o motmess motmess.c
The -lXt and -lX11 probably aren't entirely nescessary.

Here it is:

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#include <Xm/MessageB.h>
#include <Xm/Label.h>

#define OK      1
#define CANCEL  2

void dialogCB(Widget w,
           int client_data,
           XmAnyCallbackStruct *call_data)
{
  switch (client_data)
  {
        case OK:
                printf("OK selected\n");
                XtUnmanageChild(w);
                exit(2);
        case CANCEL:
                printf("CANCEL selected\n");
                XtUnmanageChild(w);
                exit(1);
  }
  XtUnmanageChild(w);
}

main(int argc, char *argv[])
{
  Widget toplevel, msg, button, dialog;
  Arg al[10];
  int ac;

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

  ac=0;
  XtSetArg(al[ac], XmNmessageString,
        XmStringCreateLtoR("Is everything OK?",
        XmSTRING_DEFAULT_CHARSET));  ac++;
  dialog = XmCreateMessageDialog(toplevel,"ok_dialog", al, ac);
  XtAddCallback (dialog, XmNokCallback, dialogCB, OK);
  XtAddCallback (dialog, XmNcancelCallback, dialogCB, CANCEL);
  XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));

  XtManageChild(dialog);

  XtRealizeWidget(toplevel);
  XtMainLoop();
}

pablo , 2003-11-11 18:30:40