we used in the source code
toplevel = XtVaAppInitialize (&app, "Hello", NULL, 0,
&argc, argv, NULL, NULL);
The widget returned by XtVaAppInitialize() is a shell widget. The shell widget acts as the top−level window
of the application and handles the application's interaction with the window manager. All of the other widgets created
by the application are created as descendents of the shell, which we'll talk about more later in this chapter. The first
argument to XtVaAppInitialize() is the address of an application context, which is a structure that Xt uses to
manage some internal data associated with an application. Most applications do not manipulate the application context
directly. Most often, an application receives an opaque pointer to an application context in the toolkit initialization call
and merely passes that pointer to a few other toolkit functions that require it as an argument. The fact that the
application context is a public variable, rather than hidden in the toolkit internals, is a forward−looking feature of Xt,
designed to support multiple threads of control.
The simpler X11R3 initialization call, XtInitialize(), is still supported by later versions of the toolkit. Its use is
discouraged because the new initialization calls provide a greater degree of upward compatibility with future
Xt−based applications. The simpler function creates an application context that is stored internally by Xt. The second
argument to XtVaAppInitialize() is a string that defines the class name of the application. A class name is
used in resource files to specify resource values that apply to all instances of an application, a widget, or a resource.
(See Volume Three, X Window System User's Guide, Motif Edition, and Volume Four, X Toolkit Intrinsics
Programming Manual, for details.) For many applications, the application class is rarely used and the class name is
important only because it is also used as the name of the application's app−defaults file.
Whenever a widget is created in Xt, its resources must have certain initial (or default) values. You can either
hard−code the values, allow them to default to widget−defined values, or specify the default values in the
app−defaults file. These default values are used unless the user has provided his own default settings in another
By convention, the class name is the same as the name of the application itself, except that the first letter is
capitalized. For example, a program named draw would have Some applications follow the convention that if the
application's name begins with an "X", the X is silent and so the second letter is capitalized as well. For example, the
class name of xterm is XTerm. a class name of Draw and an app−defaults filename of
/usr/lib/X11/app−defaults/Draw. Note, however, that there is no requirement that an app−defaults file with this name
actually be installed.
Exceptions can be made to this convention, as long as you document it. For example, all the example programs in this
book have the class name of Demos, which allows us to set certain common defaults in a single file. This technique
can be useful whenever you have a large collection of independent programs that are part of the same suite of
applications. The third and fourth arguments specify an array of objects that describe the command−line arguments for
your program, if any, and the number of arguments in the array. These arguments are unused in most of the examples
in this book and are specified as NULL and 0, respectively. The program xshowbitmap.c in the Appendix, Additional
Example Programs, provides an example of using command−line arguments. See Volume Four, X Toolkit Intrinsics
Programming Manual, for a more complete discussion of application−specific command−line arguments.
The fifth and sixth arguments contain the value (argv) and count (argc) of any actual command−line arguments.
The initialization call actually removes and acts on any arguments it recognizes, such as the standard X Toolkit
command−line options and any options that you have defined in the third argument. After this call, argv should
contain only the application name and any expected arguments such as filenames. You may want to check the
3 The Motif Programming Model 3.3.3 Initializing the Toolkit