|
楼主 |
发表于 2005-12-29 10:48:01
|
显示全部楼层
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Display *display;
int screen;
unsigned long whitePixel,blackPixel;
Window rootWindow;
void Initialise(){
display=XOpenDisplay(NULL);
screen=DefaultScreen(display);
rootWindow=DefaultRootWindow(display);
whitePixel=WhitePixel(display,screen);
blackPixel=BlackPixel(display,screen);
}
Window CreateWindow(parent,posx,posy,width,height,border)
int posx,posy;
{
Window win;
win=XCreateSimpleWindow(display,parent,posx,posy,width,height,border,blackPixel,whitePixel);
XMapWindow(display,win);
return(win);
}
main(argc,argv)
int argc;
char **argv;
{
Window win1,win2;
unsigned int width,height,border;
int posx,posy;
Colormap screen_colormap; ///
GC gc;
XColor red, brown, blue, yellow, green;
Initialise();
screen_colormap = DefaultColormap(display, DefaultScreen(display));
border=4;
width=height=400;
posx=posy=100;
win1=CreateWindow(rootWindow,posx,posy,width,height,border);
border=4;
width=height=200;
posx=posy=50;
win2=CreateWindow(win1,posx,posy,width,height,border);
gc=DefaultGC(display,screen);
XAllocNamedColor(display, screen_colormap, "blue", &blue, &blue); ///
XStoreName(display,win1,"eee");//
XStoreName(display,win2,"fff");//
XSetForeground(display, gc, blue.pixel);
XDrawLine(display,win1,gc,0,0,400,400);
XDrawString(display, win1, gc, 100, 100,"hahaha",10);
XDrawLine(display,win2,gc,0,199,199,0);
XSync(display,False);
sleep(10);
XDestroyWindow(display,win2);
XDestroyWindow(display,win1);
XCloseDisplay(display);
} |
|