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 >
C/C++ Source or Header  |  1994-01-11  |  3KB  |  133 lines

  1. /* $Id: hello.c 1.1 1994/01/12 04:36:59 ulrich Exp $ */
  2. /*
  3.  * hello.c
  4.  *
  5.  * Say "Hello, World." demo program.
  6.  */
  7.  
  8. #include <X11/Xlib.h>
  9. #include <X11/Xutil.h>
  10. #include <X11/cursorfont.h>
  11.  
  12. #include <X11/bitmaps/stipple>
  13.  
  14. char hello[] = "Hello, World.";
  15. char hi[] = "Hi!";
  16.  
  17. int
  18. main (int argc, char *argv[])
  19. {
  20.   Display *mydisplay;
  21.   Window   mywindow;
  22.   GC mygc;
  23.   XGCValues mygcvalues;
  24.   XEvent myevent;
  25.   KeySym mykey;
  26.   XSizeHints myhint;
  27.   int myscreen;
  28.   unsigned long myforeground, mybackground;
  29.   int i;
  30.   char text[10];
  31.   int done;
  32.   XColor red;
  33.   Cursor mycursor;
  34.   Pixmap mypixmap;
  35.   
  36.  
  37.   mydisplay = XOpenDisplay ("");
  38.   myscreen = DefaultScreen (mydisplay);
  39.   mybackground = WhitePixel (mydisplay, myscreen);
  40.   myforeground = BlackPixel (mydisplay, myscreen);
  41.   
  42.   myhint.x = 200; myhint.y = 300;
  43.   myhint.width = 350; myhint.height = 250;
  44.   myhint.flags = PPosition|PSize;
  45.  
  46.   mywindow = XCreateSimpleWindow (mydisplay,
  47.                   DefaultRootWindow (mydisplay),
  48.                   myhint.x, myhint.y, myhint.width, myhint.height,
  49.                   5, myforeground, mybackground);
  50.   XSetStandardProperties (mydisplay, mywindow, hello, hello,
  51.               None, argv, argc, &myhint);
  52.  
  53.   mycursor = XCreateFontCursor (mydisplay, XC_left_ptr);
  54.   XDefineCursor (mydisplay, mywindow, mycursor);
  55.  
  56.   mygc = XCreateGC (mydisplay, mywindow, 0, 0);
  57.   mypixmap = XCreateBitmapFromData (mydisplay, mywindow, 
  58.                     stipple_bits, stipple_width, stipple_height);
  59.  
  60.   mygcvalues.foreground = myforeground;
  61.   mygcvalues.background = mybackground;
  62.   mygcvalues.fill_style = FillStippled;
  63.   mygcvalues.stipple = mypixmap;
  64.   XChangeGC (mydisplay, mygc,
  65.          GCForeground | GCBackground | GCFillStyle | GCStipple, &mygcvalues);
  66.  
  67.   XAllocNamedColor (mydisplay,
  68.             DefaultColormap (mydisplay, myscreen),
  69.             "red", &red, &red);
  70.  
  71.   XSelectInput (mydisplay, mywindow,
  72.         ButtonPressMask
  73.         | KeyPressMask
  74.         | ExposureMask
  75.         | EnterWindowMask
  76.         | LeaveWindowMask);
  77.  
  78.   XMapRaised (mydisplay, mywindow);
  79.   
  80.   done = 0;
  81.   while (done == 0) {
  82.  
  83.     fvwm();
  84.     if (!XPending(mydisplay)) continue;
  85.  
  86.     XNextEvent (mydisplay, &myevent);
  87.  
  88. #ifdef DEBUG
  89.     _XPrintEvent (mydisplay, &myevent);
  90. #endif
  91.  
  92.     switch (myevent.type) 
  93.       {
  94.       case Expose:
  95.     if (myevent.xexpose.count == 0)
  96.       XDrawImageString (myevent.xexpose.display,
  97.                 myevent.xexpose.window,
  98.                 mygc,
  99.                 50, 50,
  100.                 hello, strlen (hello));
  101.     break;
  102.  
  103.       case ButtonPress:
  104.     XDrawImageString (myevent.xbutton.display,
  105.               myevent.xbutton.window,
  106.               mygc,
  107.               myevent.xbutton.x, myevent.xbutton.y,
  108.               hi, strlen (hi));
  109.     break;
  110.     
  111.       case KeyPress:
  112.     i = XLookupString (&myevent.xkey, text, 10, &mykey, 0);
  113.     if (i == 1 && text[0] == 'q') done = 1;
  114.     break;
  115.  
  116.       case EnterNotify:
  117.     XSetWindowBorder (mydisplay, myevent.xcrossing.window, red.pixel);
  118.     break;
  119.  
  120.       case LeaveNotify:
  121.     XSetWindowBorder (mydisplay, myevent.xcrossing.window, myforeground);
  122.     break;
  123.       }
  124.   }
  125.   XFreeGC (mydisplay, mygc);
  126.   XDestroyWindow (mydisplay, mywindow);
  127. #ifdef DEBUG
  128.   _XPrintTree (mydisplay, DefaultRootWindow (mydisplay), 0);
  129. #endif
  130.   XCloseDisplay (mydisplay);
  131.   exit (0);
  132. }
  133.