The best way to understand how to use any programming library is by trying some simple examples. A collection of example programs that introduces some of the widgets in the Motif widget set can be found in the directory
/usr/units/Xm
You can now create your first Motif program (see later to retrieve it):
/*
* xmhello.c - simple program to put up a banner on the display
*/
/*
* Header files required for all Toolkit programs
*/
#include <X11/Intrinsic.h> /* Intrinsics definitions */
#include <Xm/Xm.h> /* Standard Motif definitions */
/*
* Public header file for widgets actually used in this file.
*/
#include <Xm/Label.h> /* Motif Label Widget */
main(argc, argv)
int argc;
char **argv;
{
XtAppContext app_context;
Widget topLevel, hello;
topLevel = XtVaAppInitialize(
&app_context, /* Application context */
"XMhello", /* Application class */
NULL, 0, /* command line option list */
&argc, argv, /* command line args */
NULL, /* for missing app-defaults file */
NULL); /* terminate varargs list */
hello = XtVaCreateManagedWidget(
"hello", /* arbitrary widget name */
xmLabelWidgetClass, /* widget class from Label.h */
topLevel, /* parent widget */
NULL); /* terminate varargs list */
/*
* Create windows for widgets and map them.
*/
XtRealizeWidget(topLevel);
/*
* Loop for events.
*/
XtAppMainLoop(app_context);
}
#include <Motif.tmpl>
LOCAL_LIBRARIES = $(XMLIB) $(SYSLIBS)
FILE = xmhello
SRCS = $(FILE).c
OBJS = $(FILE).o
PROGRAM = $(FILE)
ComplexProgramTarget($(FILE))
After retrieving and saving the code plus Imakefile, you
should be able to type:
xmkmf -a ; make FILE=xmhello
This will produce the executable called xmhello.
It is possible to execute a (different) xmhello 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