home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Shareware 1999 March
/
PCShareware-3-99.iso
/
IMPLE
/
DJGPP.RAR
/
DJGPP2
/
XLIB-SR0.ZIP
/
SRC
/
XLIBEMU
/
HELLO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-11
|
3KB
|
133 lines
/* $Id: hello.c 1.1 1994/01/12 04:36:59 ulrich Exp $ */
/*
* hello.c
*
* Say "Hello, World." demo program.
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/bitmaps/stipple>
char hello[] = "Hello, World.";
char hi[] = "Hi!";
int
main (int argc, char *argv[])
{
Display *mydisplay;
Window mywindow;
GC mygc;
XGCValues mygcvalues;
XEvent myevent;
KeySym mykey;
XSizeHints myhint;
int myscreen;
unsigned long myforeground, mybackground;
int i;
char text[10];
int done;
XColor red;
Cursor mycursor;
Pixmap mypixmap;
mydisplay = XOpenDisplay ("");
myscreen = DefaultScreen (mydisplay);
mybackground = WhitePixel (mydisplay, myscreen);
myforeground = BlackPixel (mydisplay, myscreen);
myhint.x = 200; myhint.y = 300;
myhint.width = 350; myhint.height = 250;
myhint.flags = PPosition|PSize;
mywindow = XCreateSimpleWindow (mydisplay,
DefaultRootWindow (mydisplay),
myhint.x, myhint.y, myhint.width, myhint.height,
5, myforeground, mybackground);
XSetStandardProperties (mydisplay, mywindow, hello, hello,
None, argv, argc, &myhint);
mycursor = XCreateFontCursor (mydisplay, XC_left_ptr);
XDefineCursor (mydisplay, mywindow, mycursor);
mygc = XCreateGC (mydisplay, mywindow, 0, 0);
mypixmap = XCreateBitmapFromData (mydisplay, mywindow,
stipple_bits, stipple_width, stipple_height);
mygcvalues.foreground = myforeground;
mygcvalues.background = mybackground;
mygcvalues.fill_style = FillStippled;
mygcvalues.stipple = mypixmap;
XChangeGC (mydisplay, mygc,
GCForeground | GCBackground | GCFillStyle | GCStipple, &mygcvalues);
XAllocNamedColor (mydisplay,
DefaultColormap (mydisplay, myscreen),
"red", &red, &red);
XSelectInput (mydisplay, mywindow,
ButtonPressMask
| KeyPressMask
| ExposureMask
| EnterWindowMask
| LeaveWindowMask);
XMapRaised (mydisplay, mywindow);
done = 0;
while (done == 0) {
fvwm();
if (!XPending(mydisplay)) continue;
XNextEvent (mydisplay, &myevent);
#ifdef DEBUG
_XPrintEvent (mydisplay, &myevent);
#endif
switch (myevent.type)
{
case Expose:
if (myevent.xexpose.count == 0)
XDrawImageString (myevent.xexpose.display,
myevent.xexpose.window,
mygc,
50, 50,
hello, strlen (hello));
break;
case ButtonPress:
XDrawImageString (myevent.xbutton.display,
myevent.xbutton.window,
mygc,
myevent.xbutton.x, myevent.xbutton.y,
hi, strlen (hi));
break;
case KeyPress:
i = XLookupString (&myevent.xkey, text, 10, &mykey, 0);
if (i == 1 && text[0] == 'q') done = 1;
break;
case EnterNotify:
XSetWindowBorder (mydisplay, myevent.xcrossing.window, red.pixel);
break;
case LeaveNotify:
XSetWindowBorder (mydisplay, myevent.xcrossing.window, myforeground);
break;
}
}
XFreeGC (mydisplay, mygc);
XDestroyWindow (mydisplay, mywindow);
#ifdef DEBUG
_XPrintTree (mydisplay, DefaultRootWindow (mydisplay), 0);
#endif
XCloseDisplay (mydisplay);
exit (0);
}