/****** w7.C ******/ #include #include #include #include #include #include int main() { Display *disp; int ScrNum; GC prGC; XEvent Evnt; Window win; int i=0,n_call=0; char str[100]="Hello world!";//,s[100]="*"; XPoint points[] = { {10,10}, {1,0}, {1,0}, {1,0}, {1,0}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1} }; int n_points = 11; if ( (disp = XOpenDisplay (NULL)) == NULL) { printf("\n====1"); exit(1); } ScrNum = DefaultScreen( disp ); win = XCreateSimpleWindow( disp, RootWindow( disp, ScrNum), 0, 0, 100, 100, 2, BlackPixel( disp, ScrNum), WhitePixel( disp, ScrNum) ); XSelectInput( disp, win, ExposureMask | KeyPressMask | ButtonPressMask); XMapWindow (disp,win); while( 1 ) { XNextEvent( disp, &Evnt); switch (Evnt.type) { case ButtonPress: prGC = XCreateGC( disp, win, 0, NULL ); XSetForeground( disp, prGC, BlackPixel(disp, 0) ); points[0].x = i; points[0].y = i; XDrawPoints(disp, win, prGC, points, n_points, CoordModePrevious); XFreeGC( disp, prGC ); i+=10; break; case Expose: if ( Evnt.xexpose.count!=0 ) break; prGC = XCreateGC( disp, win, 0, NULL ); XSetForeground( disp, prGC, BlackPixel(disp, 0) ); XDrawString( disp, win, prGC, 10,50, str, strlen(str) ); XFreeGC( disp, prGC ); n_call++; sprintf(str,"Hello... %d",n_call); break; case KeyPress: goto fin; } } fin: XCloseDisplay( disp ); return 0; }