LINUX - XT PROGRAM EXAMPLE 1

This example uses the X Toolkit Intrinsics to create and open a window - this is much simpler than just using X to do the same job.

New concepts include:

Widgets - These are "User-Interface' components, such as buttons, scrollbars, ... In this case, the main window is created as a widget.

Go here to get some simplified X Window and X Toolkit Intrinsics Documentation on calls used in this example

Create a file named "demo_xt1.cpp" with the contents shown in the box:
#include <X11/IntrinsicP.h> // IntrinsicP.h has some faster macros than Intrinsic.h
#include <X11/ShellP.h> // Needed for Widget class definitions
XtAppContext app;
Widget main_widget; //Main Window
//------------------------------------------------
int main (int argc, char **argv)
{
short unsigned int xx,yy;
//--- Create and initialize the top-level widget
main_widget = XtOpenApplication(&app, "My Application", NULL, 0, &argc, argv, NULL, applicationShellWidgetClass, NULL, 0);
//--- Make it the desired size
XtMakeResizeRequest(main_widget, 400, 100, &xx, &yy);
//--- Realize the main widget
XtRealizeWidget(main_widget);

//-----
XtAppMainLoop(app);

}

XtOpenApplication - initializes the X Toolkit internals. (Note that this replaces XtAppInitialize)
XtMakeResizeRequest - Controls the initial size of the window. Without this, Window creation fails since the size is still zero.
XtRealizeWidget - Actually creates the window for the Widget.
XtAppMainLoop - Constitutes the main loop of X Toolkit applications. Without this, the program starts, the immediately exits.

To compile and link this program, type
g++ -o demo_xt1 demo_xt1.cpp -I/usr/X11R6/include -L/usr/X11R6/lib -lX11 -lXt
This will compile and link demo_xt1.cpp into the executable file demo_xt1
Now type
./demo_xt1
and a window should now appear