jlf@earth.cray.COM (John Freeman) (02/08/89)
I'm trying to put together some examples for a class I'm
teaching on Toolkit programming. I want to discuss
application contexts, but don't quite understand their use
and meaning. Could someone give me a definition?
The one example I'm trying to work out is to use application
contexts to do "Hello, World" on two displays, using the
toolkit. As a preliminary step, I rewrote the now famous
hw.c to use XtToolkitInitialize() and XtCreateApplicationContext(),
and it doesn't work. The code below demonstrates the problem.
If I pass a NULL pointer to XtOpenDisplay as the Application
Context parameter, it works. If I pass the real XtAppContext
returned from the XtCreateApplicationContext(), the program
never displays anything - it goes into XtMainLoop(), but
nothing happens.
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Label.h>
#include <stdio.h>
#define STRING "Hello, World!"
Arg label_args[] = {XtNlabel, (XtArgVal) STRING };
Arg argies[5];
main(argc,argv)
int argc;
char **argv;
{
Widget toplevel, label1, label2;
Display *d1p, *d2p;
XtAppContext app1, app2;
XtToolkitInitialize();
app1 = XtCreateApplicationContext();
/**** This works ****/
d1p = XtOpenDisplay(NULL, NULL, NULL, "Xlabel", NULL, 0, &argc, argv);
#if 0
/**** This doesn't ****/
d1p = XtOpenDisplay(app1, NULL, NULL, "Xlabel", NULL, 0, &argc, argv);
#endif
if (d1p == NULL) { printf("XtOpenDisplay failed\n"); return; }
argies[0].name = XtNscreen;
argies[0].value = (XtArgVal) DefaultScreenOfDisplay(d1p);
toplevel = XtAppCreateShell("XShell", "xshell",
applicationShellWidgetClass, d1p, argies, 1);
label1 = XtCreateWidget(argv[0], labelWidgetClass,
toplevel, label_args, XtNumber(label_args));
XtManageChild(label1);
XtRealizeWidget(toplevel);
XtMainLoop();
}