Win32 / Ili.............
5 отговора
253 прегледа
Win32 / Ili.............
An example of a real X program follows. This is about the simplest an X program is ever going to get. The program displays a small XPM image file in a window and waits for a key press or mouse click before exiting. You can compile it with gcc -o splash splash.c -lX11 -L/usr/X11R6/lib. (You can see right away why there are few applications written directly in X.) Notice that all X library functions are prefixed by an X.
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
130
135
140
145
150
155
160
165
170
175
180
185
190
195
200
205
210
215
/*splash.c-displayanimage*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<X11/Xlib.h>
/*XPM*/
staticchar*graham_splash[]={
/*columnsrowscolorschars-per-pixel*/
"2832161",
"c#34262e",".c#4c3236","Xc#673a39","oc#543b44",
"Oc#724e4e","+c#6a5459","@c#6c463c","#c#92706c",
"$c#92685f","%c#987e84","&c#aa857b","nc#b2938f",
"=c#bca39b","-c#a89391",";c#c4a49e",":c#c4a8a4",
/*pixels*/
"--%#%%nnnn#-nnnnnn=====;;=;:","--------n-nnnnnn=n==;==;=:;:",
"----n--n--n-n-n-nn===:::::::","-----&------nn-n=n====::::::",
"----------------n===;=::::::","----%&-%--%##%---n===:::::::",
"------%#%+++o+++----=:::::::","--#-%%#+++oo.oo+#--=:::::::",
"-%%%%++++o...++&-==:::::","---%#+#+++o.oo+&n=::::",
"--%###+$+++Oo.o+#-:=::","-&%########++Oo@$-==:",
"####$$$+###$++OX.O+&==","&##$O+OXo+++$#+Oo...O&&-",
"&##+OX......oOO@@...o@+&&","&###$Oo.o++..oX@oo@O$&-",
"n###$$$$O$o...X...XXX@$$$&","nnn##$$#$OO..XX+@.XXX@$$#&",
"nnn&&%####$OX.X$$@.XX$$$$&","nnnnn&&###$$$OX$$X..XXX@O$&n",
"nnnnnn&&%###$$$$@XXXXX@O$&&n",";n=;nnnn&&&#$$$$$@@@@@@O$&n;",
";n;=nn;nnnn#&$$$@X@O$@@$$&n;","=n=;;;n;;nn&&&$$$$OO$$$$$&;;",
"n;=n;;=nn&n&&&&&&$$$$$##&&n;","n;=;;;;;;;;&&&n&&&&&&&&#&n=;",
";n;n;;=n;&;&;&n&&&&&&&#nn;;;","n;=;;;;;;;;n;&&n&&&n&nnnn;;;",
"n=;;:;;=;;nn;&n;&n&nnnnnnn=;","nn;;;;;;;;;;;;;;n&nnnnnn===;",
"=nn;;:;n;;;;&&&&n&&nnnnnn;=;","n====;;;;&&&&&&&nnnnnnnnnn;;"
};
intmain(intargc,char**argv)
{
inti,j,x,y,width,height,n_colors;
XSetWindowAttributesxswa;
XGCValuesgcv;
Display*display;
char*display_name=0;
intdepth=0;
Visual*visual;
Windowwindow;
Pixmappixmap;
XImage*image;
Colormapcolormap;
GCgc;
intbytes_per_pixel;
unsignedlongcolors[256];
unsignedchar**p,*q;
for(i=1;i<argc-1;i++)
if(argv)
if(!strcmp(argv,"-display"))
display_name=argv[i+1];
display=XOpenDisplay(display_name);
if(!display){
printf("splash:cannotopendisplay\n");
exit(1);
}
depth=DefaultDepth(display,DefaultScreen(display));
visual=DefaultVisual(display,DefaultScreen(display));
p=(unsignedchar**)graham_splash;
q=p[0];
width=atoi((constchar*)q);
q=(unsignedchar*)strchr(q,'');
height=atoi((constchar*)++q);
q=(unsignedchar*)strchr(q,'');
n_colors=atoi((constchar*)++q);
colormap=DefaultColormap(display,DefaultScreen(display));
pixmap=
XCreatePixmap(display,DefaultRootWindow(display),width,height,
depth);
gc=XCreateGC(display,pixmap,0,&gcv);
image=
XCreateImage(display,visual,depth,ZPixmap,0,0,width,height,
8,0);
image->data=(char*)malloc(image->bytes_per_line*height+16);
/*createcolorpalette*/
for(p=p+1,i=0;i<n_colors;p++,i++){
XColorc,c1;
unsignedchar*x;
x=*p+4;
if(*x=='#'){
unsignedchar*h=(unsignedchar*)"0123456789abcdef";
x++;
c.red=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.red|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
c.green=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.green|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
c.blue=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.blue|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
if(!XAllocColor(display,colormap,&c))
printf("splash:couldnotallocatecolorcell\n");
}else{
if(!XAllocNamedColor(display,colormap,(char*)x,&c,&c1))
printf("splash:couldnotallocatecolorcell\n");
}
colors[(*p)[0]]=c.pixel;
}
bytes_per_pixel=image->bytes_per_line/width;
/*copewithservershavingdifferentbyteorderinganddepths*/
for(j=0;j<height;j++,p++){
unsignedchar*r;
unsignedlongc;
q=image->data+image->bytes_per_line*j;
r=*p;
if(image->byte_order==MSBFirst){
switch(bytes_per_pixel){
case4:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>24;
*q++=c>>16;
*q++=c>>8;
*q++=c;
}
break;
case3:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>16;
*q++=c>>8;
*q++=c;
}
break;
case2:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>8;
*q++=c;
}
break;
case1:
for(i=0;i<width;i++)
*q++=colors[*r++];
break;
}
}else{
switch(bytes_per_pixel){
case4:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
*q++=c>>16;
*q++=c>>24;
}
break;
case3:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
*q++=c>>16;
}
break;
case2:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
}
break;
case1:
for(i=0;i<width;i++)
*q++=colors[*r++];
break;
}
}
}
XPutImage(display,pixmap,gc,image,0,0,0,0,width,height);
x=(DisplayWidth(display,DefaultScreen(display))-width)/2;
y=(DisplayHeight(display,DefaultScreen(display))-height)/2;
xswa.colormap=colormap;
xswa.background_pixmap=pixmap;
window=
XCreateWindow(display,DefaultRootWindow(display),x,y,width,
height,0,depth,InputOutput,visual,
CWColormap|CWBackPixmap,&xswa);
XSelectInput(display,window,KeyPressMask|ButtonPressMask);
XMapRaised(display,window);
while(1){
XEventevent;
XNextEvent(display,&event);
if(event.xany.type==KeyPress||event.xany.type==ButtonPressMask)
break;
}
XUnmapWindow(display,window);
XCloseDisplay(display);
return0;
}
You can learn to program X from the documentation in the X Window System sources--see below. The preceding program is said to be ``written directly in X-lib'' because it links only with the lowest-level X library, libX11.so. The advantage of developing this way is that your program will work across every variant of UNIX without any modifications. Notice also that the program deals with any type of display device regardless of its resolution (widthxheight or pixels-per-inch), color capacity, or hardware design.
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
130
135
140
145
150
155
160
165
170
175
180
185
190
195
200
205
210
215
/*splash.c-displayanimage*/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<X11/Xlib.h>
/*XPM*/
staticchar*graham_splash[]={
/*columnsrowscolorschars-per-pixel*/
"2832161",
"c#34262e",".c#4c3236","Xc#673a39","oc#543b44",
"Oc#724e4e","+c#6a5459","@c#6c463c","#c#92706c",
"$c#92685f","%c#987e84","&c#aa857b","nc#b2938f",
"=c#bca39b","-c#a89391",";c#c4a49e",":c#c4a8a4",
/*pixels*/
"--%#%%nnnn#-nnnnnn=====;;=;:","--------n-nnnnnn=n==;==;=:;:",
"----n--n--n-n-n-nn===:::::::","-----&------nn-n=n====::::::",
"----------------n===;=::::::","----%&-%--%##%---n===:::::::",
"------%#%+++o+++----=:::::::","--#-%%#+++oo.oo+#--=:::::::",
"-%%%%++++o...++&-==:::::","---%#+#+++o.oo+&n=::::",
"--%###+$+++Oo.o+#-:=::","-&%########++Oo@$-==:",
"####$$$+###$++OX.O+&==","&##$O+OXo+++$#+Oo...O&&-",
"&##+OX......oOO@@...o@+&&","&###$Oo.o++..oX@oo@O$&-",
"n###$$$$O$o...X...XXX@$$$&","nnn##$$#$OO..XX+@.XXX@$$#&",
"nnn&&%####$OX.X$$@.XX$$$$&","nnnnn&&###$$$OX$$X..XXX@O$&n",
"nnnnnn&&%###$$$$@XXXXX@O$&&n",";n=;nnnn&&&#$$$$$@@@@@@O$&n;",
";n;=nn;nnnn#&$$$@X@O$@@$$&n;","=n=;;;n;;nn&&&$$$$OO$$$$$&;;",
"n;=n;;=nn&n&&&&&&$$$$$##&&n;","n;=;;;;;;;;&&&n&&&&&&&&#&n=;",
";n;n;;=n;&;&;&n&&&&&&&#nn;;;","n;=;;;;;;;;n;&&n&&&n&nnnn;;;",
"n=;;:;;=;;nn;&n;&n&nnnnnnn=;","nn;;;;;;;;;;;;;;n&nnnnnn===;",
"=nn;;:;n;;;;&&&&n&&nnnnnn;=;","n====;;;;&&&&&&&nnnnnnnnnn;;"
};
intmain(intargc,char**argv)
{
inti,j,x,y,width,height,n_colors;
XSetWindowAttributesxswa;
XGCValuesgcv;
Display*display;
char*display_name=0;
intdepth=0;
Visual*visual;
Windowwindow;
Pixmappixmap;
XImage*image;
Colormapcolormap;
GCgc;
intbytes_per_pixel;
unsignedlongcolors[256];
unsignedchar**p,*q;
for(i=1;i<argc-1;i++)
if(argv)
if(!strcmp(argv,"-display"))
display_name=argv[i+1];
display=XOpenDisplay(display_name);
if(!display){
printf("splash:cannotopendisplay\n");
exit(1);
}
depth=DefaultDepth(display,DefaultScreen(display));
visual=DefaultVisual(display,DefaultScreen(display));
p=(unsignedchar**)graham_splash;
q=p[0];
width=atoi((constchar*)q);
q=(unsignedchar*)strchr(q,'');
height=atoi((constchar*)++q);
q=(unsignedchar*)strchr(q,'');
n_colors=atoi((constchar*)++q);
colormap=DefaultColormap(display,DefaultScreen(display));
pixmap=
XCreatePixmap(display,DefaultRootWindow(display),width,height,
depth);
gc=XCreateGC(display,pixmap,0,&gcv);
image=
XCreateImage(display,visual,depth,ZPixmap,0,0,width,height,
8,0);
image->data=(char*)malloc(image->bytes_per_line*height+16);
/*createcolorpalette*/
for(p=p+1,i=0;i<n_colors;p++,i++){
XColorc,c1;
unsignedchar*x;
x=*p+4;
if(*x=='#'){
unsignedchar*h=(unsignedchar*)"0123456789abcdef";
x++;
c.red=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.red|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
c.green=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.green|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
c.blue=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<12;
c.blue|=
((unsignedlong)strchr(h,*x++)-
(unsignedlong)h)<<8;
if(!XAllocColor(display,colormap,&c))
printf("splash:couldnotallocatecolorcell\n");
}else{
if(!XAllocNamedColor(display,colormap,(char*)x,&c,&c1))
printf("splash:couldnotallocatecolorcell\n");
}
colors[(*p)[0]]=c.pixel;
}
bytes_per_pixel=image->bytes_per_line/width;
/*copewithservershavingdifferentbyteorderinganddepths*/
for(j=0;j<height;j++,p++){
unsignedchar*r;
unsignedlongc;
q=image->data+image->bytes_per_line*j;
r=*p;
if(image->byte_order==MSBFirst){
switch(bytes_per_pixel){
case4:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>24;
*q++=c>>16;
*q++=c>>8;
*q++=c;
}
break;
case3:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>16;
*q++=c>>8;
*q++=c;
}
break;
case2:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c>>8;
*q++=c;
}
break;
case1:
for(i=0;i<width;i++)
*q++=colors[*r++];
break;
}
}else{
switch(bytes_per_pixel){
case4:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
*q++=c>>16;
*q++=c>>24;
}
break;
case3:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
*q++=c>>16;
}
break;
case2:
for(i=0;i<width;i++){
c=colors[*r++];
*q++=c;
*q++=c>>8;
}
break;
case1:
for(i=0;i<width;i++)
*q++=colors[*r++];
break;
}
}
}
XPutImage(display,pixmap,gc,image,0,0,0,0,width,height);
x=(DisplayWidth(display,DefaultScreen(display))-width)/2;
y=(DisplayHeight(display,DefaultScreen(display))-height)/2;
xswa.colormap=colormap;
xswa.background_pixmap=pixmap;
window=
XCreateWindow(display,DefaultRootWindow(display),x,y,width,
height,0,depth,InputOutput,visual,
CWColormap|CWBackPixmap,&xswa);
XSelectInput(display,window,KeyPressMask|ButtonPressMask);
XMapRaised(display,window);
while(1){
XEventevent;
XNextEvent(display,&event);
if(event.xany.type==KeyPress||event.xany.type==ButtonPressMask)
break;
}
XUnmapWindow(display,window);
XCloseDisplay(display);
return0;
}
You can learn to program X from the documentation in the X Window System sources--see below. The preceding program is said to be ``written directly in X-lib'' because it links only with the lowest-level X library, libX11.so. The advantage of developing this way is that your program will work across every variant of UNIX without any modifications. Notice also that the program deals with any type of display device regardless of its resolution (widthxheight or pixels-per-inch), color capacity, or hardware design.
Re: Win32 / Ili.............
може ли на български, че вече съм се превключил на него и не разбирам за какво става дума, но щом е на инлглизе - си е 15 зелени кинта в час ин адванс.
мързи ме да гледам след първия екран, все са същите боклуци
-----------------------
гърбавия, ковчег ще го изправи
мързи ме да гледам след първия екран, все са същите боклуци
-----------------------
гърбавия, ковчег ще го изправи
Редактирано от Дpeмeщ на
Re: Win32 / Ili.............
дал си някакъв пример... което е добре.
а защо не драсна две думи отдолу та да знаем какво се опитваш да кажеш/докажеш?
--
"Agile is a mindset, not a set of practices, rules, or tools."
Tom Poppendieck
а защо не драсна две думи отдолу та да знаем какво се опитваш да кажеш/докажеш?
--
"Agile is a mindset, not a set of practices, rules, or tools."
Tom Poppendieck
Re: Win32 / Ili.............
Opitva se kaje (i e prav), che API-to na X11 ne e po-prosto za direktna upotreba, otkolkoto Windows GDI. Nishto novo, ele pyk interesno.
Re: Win32 / Ili.............
sledwashtia primer ste e iztegliane na jpg ot ftp site i vizualizirane.
stawa s 1 red na javascript :)
a w C e tolkowa uslojneno
stawa s 1 red na javascript :)
a w C e tolkowa uslojneno
Re: Win32 / Ili.............
от скоро си играя да правя гуи-та с python и Tk ( Tkinter ). голям кеф, супер лесно... и върви на юникси и уиндоуси
ама зависи какво ти трябва нали?
--
"Agile is a mindset, not a set of practices, rules, or tools."
Tom Poppendieck
ама зависи какво ти трябва нали?
--
"Agile is a mindset, not a set of practices, rules, or tools."
Tom Poppendieck