/****** w4.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,x,y; char str[100]="Hello world!";//,s[100]="*"; 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) ); XDrawLine(disp, win, prGC, i*10,i*i, (i+1)*10,(i+1)*(i+1) ); XFreeGC( disp, prGC ); x=Evnt.xbutton.x; y=Evnt.xbutton.y; printf("\nx=%d y=%d\n",x,y); i++; 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; }