1.5. Your second Motif Program   

You can now create your second Motif program (see later to retrieve it):

    #include <stdio.h>

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
void main();
void activate_cb(); /* Callback for the PushButton */
static void Syntax(app_con, call)
XtAppContext app_con;
char *call;
{
XtDestroyApplicationContext(app_con);
fprintf( stderr, "Usage: %s\n", call);
exit(1);
}
void main (argc,argv)
unsigned int argc;
char **argv;
{
Widget toplevel; /* Shell widget */
Widget button; /* PushButton widget */
XtAppContext app_context;
XmString btn_text; /* button label pointer for compound string */
toplevel = XtVaAppInitialize( &app_context, /* Application context */
"XMcommand", /* Application class */
NULL, 0, /* command line option list */
&argc, argv, /* command line args */
NULL, /* for missing app-defaults file */
NULL); /* terminate varargs list */
if (argc != 1)
Syntax(app_context, argv[0]);
/* create compound string for the button text */
btn_text = XmStringCreateLtoR("Click on me please!", XmSTRING_DEFAULT_CHARSET);
/* create button */
button = XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, toplevel,
XmNlabelType, XmSTRING,
XmNlabelString, btn_text,
XmNwidth, 250,
XmNheight, 150,
NULL);
XtAddCallback (button, XmNactivateCallback, activate_cb, "Hi There!");
XtRealizeWidget (toplevel);
XtAppMainLoop(app_context);
}
void activate_cb (widget_cb, client_data, call_data)
Widget widget_cb; /* widget id */
XtPointer client_data; /* data from application */
XtPointer call_data; /* data from widget class */
{
char *string = (char *) client_data;
XmString xm_label_string;
char *label_string;
XtVaGetValues(widget_cb,
XmNlabelString, &xm_label_string,
NULL);
XmStringGetLtoR(xm_label_string,
XmSTRING_DEFAULT_CHARSET,
&label_string);
fprintf(stdout, "Button
label_string,string);
label_string = XmStringCreateLtoR("New Label", XmSTRING_DEFAULT_CHARSET);
XtVaSetValues(widget_cb,
XmNlabelString,label_string,
NULL);
}

You will also need to have an Imakefile:

    #include <Motif.tmpl>

LOCAL_LIBRARIES = $(XMLIB) $(SYSLIBS)
FILE = xmhello
SRCS = $(FILE).c
OBJS = $(FILE).o
PROGRAM = $(FILE)
ComplexProgramTarget($(FILE))

The alternative would be for you to grab the source code (via ) and compile it on your machine.
Imakefile xmcommand.c

After retrieving and saving the code plus Imakefile, you should be able to type:
xmkmf -a ; make FILE=xmcommand
This will produce the executable called xmcommand.

It is possible to execute a (different) xmcommand program and display it on your screen. To run it, your system must be running X and the server control is set to xhost . Also it will not work if you are using a proxy server or you are running your browser on a machine different from the one you are displaying it on. Many example programs are available