This is HW_Xonly.c in view mode; [Download] [Up]
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <ieeefp.h>
int isinf(double d) {return !finite(d);}
/*
* The following declarations are part of the mechanism that
* calls the Redisplay procedure whenever the contents need
* to be updated.
*/
void Redisplay();
String translations = "<Expose> : Redisplay()";
XtActionsRec actions[] = { {"Redisplay", Redisplay} };
Display *display; /* Connection to the X server */
Window window; /* Window that we'll draw in */
GC gc; /* X graphics context */
void main(argc, argv)
int argc;
char **argv;
{
Widget appShell, w;
XtAppContext app;
Font font;
/*
* The call to XtAppInitialize creates a connection to the
* X server. We extract that connection with the call to
* XtDisplay()
*/
appShell = XtAppInitialize(&app, "Demo", NULL, 0, &argc, argv,
NULL, NULL, 0);
display = XtDisplay(appShell);
/*
* XtAppAddActions adds Redisplay as an action procedure that
* is called when an Expose event is received by the widget.
*/
XtAppAddActions(app, actions, XtNumber(actions));
/*
* Now we can create the window. First we set up some parameters
* like width and height. The call to XtVaCreateManagedWidget and
* XtRealize create and initialize the window. We extract the
* window identifier with the XtWindow call.
*/
w = XtVaCreateManagedWidget("main", coreWidgetClass, appShell,
XtNwidth, 600,
XtNheight, 400,
XtNtranslations, XtParseTranslationTable(translations),
NULL);
XtRealizeWidget(appShell);
window = XtWindow(w);
/*
* The following creates an X graphics context and sets the
* foreground color of the graphics context to black
*/
gc = XCreateGC(display, window, 0, NULL);
XSetForeground(display, gc, XBlackPixelOfScreen(XtScreen(w)));
font = XLoadFont(display, "helvetica-90");
XSetFont(display, gc, font);
XtAppMainLoop(app);
}
/*
* The Redisplay procedure is called whenever the
* contents of the window needs to be repainted.
*/
void Redisplay(w, event, params, num)
Widget w;
XEvent *event;
String *params;
Cardinal *num;
{
/*
* The following lines select the X font "Fixed", install
* that font in the X graphics context, and finally display
* the string. The XFlush call ensures that everything gets
* executed by X now.
*/
XDrawString(display, window, gc, 72, 72, "Hello World", 11);
XSync(display, 0);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.