Bonjour à tous les Linuxiens :
j'ai récement sorti de mes cartons un vieux bouquin sur le système XWindow;
Je vous livre le code du premier programme exemple :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
#include </usr/X11R6/include/X11/Xlib.h>
#include </usr/X11R6/include/X11/Xutil.h>
 
char	hello[]="How do you do ?";
char	texte_clic[]="-yau de poêle!";
 
int main (int argc,char **argv)
{
	Display *canal_aff;
	Window *fenetre;
	GC contx_graph;
	XEvent evenem;
	KeySym touche;
	XSizeHints infos_fen;
	XWMHints infos_WM;
	int test_boucle,ecran,i;
	unsigned long couleur_AVplan,couleur_ARRplan;
	char frappe[10];
 
	canal_aff=XOpenDisplay("");
	ecran=DefaultScreen(canal_aff);
 
	couleur_ARRplan=WhitePixel(canal_aff,ecran);
	couleur_AVplan=BlackPixel(canal_aff,ecran);
 
	infos_fen.x=200;
	infos_fen.y=300;
	infos_fen.width=350;
	infos_fen.height=250;
	infos_fen.flags=PPosition | PSize;
	infos_WM.flags=InputHint;
	infos_WM.input=True;
 
	fenetre=XCreateSimpleWindow(canal_aff,DefaultRootWindow(canal_aff),
			infos_fen.x,infos_fen.y,
			infos_fen.width,infos_fen.height,5,
			couleur_AVplan,couleur_ARRplan);
	XSetStandardProperties(canal_aff,fenetre,hello,hello,None,
			argv,argc,&infos_fen);
	XSetWMHints(canal_aff,fenetre,&infos_WM);
 
	contx_graph=XCreateGC(canal_aff,fenetre,0,0);
	XSetBackground(canal_aff,contx_graph,couleur_ARRplan);
	XSetForeground(canal_aff,contx_graph,couleur_AVplan);
 
	XSelectInput=(canal_aff,fenetre,
		ButtonPressMask | KeyPressMask | ExposureMask);
 
	XMapRaised(canal_aff,fenetre);
 
	test_boucle=0;
	while(test_boucle == 0)
	{
		XNextEvent(canal_aff,&evenem);
		switch(evenem.type)
		{
			case Expose:
				if(evenem.xexpose.count == 0)
					XDrawImage(evenem.xexpose.display,
					 evenem.xexpose.window,contx_graph,
				 	 50,50,hello,strlen(hello));
		       		break;
			case MappingNotify:
				XRefreshKeyboardMapping(&evenem);
				break;
			case ButtonPress:
				XDrawImageString(evenem.xbutton.display,
				 evenem.xbutton.window,contx_graph,
		 		 evenem.xbutton.x,evenem.xbutton.y,
				 texte_clic,strlen(texte_clic));
	       			break;
			case KeyPress:
				i=XLookupString(&evenem,frappe,10,&touche,0);
				if(i==1 && frappe[0]=='q') test_boucle=1;
				break;
		}
	}
	XFreeGC(canal_aff,contx_graph);
	XDestroyWindow(canal_aff,fenetre);
	XCloseDisplay(canal_aff);
 
	exit(0);
}
Malheureusement la compilation pose problème :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
hello.c: In function `main':
hello.c:37: warning: assignment makes pointer from integer without a cast
hello.c:39: warning: passing arg 2 of `XSetStandardProperties' makes integer from pointer without a cast
hello.c:40: warning: passing arg 2 of `XSetWMHints' makes integer from pointer without a cast
hello.c:42: warning: passing arg 2 of `XCreateGC' makes integer from pointer without a cast
hello.c:47: error: invalid lvalue in assignment
hello.c:49: warning: passing arg 2 of `XMapRaised' makes integer from pointer without a cast
hello.c:64: warning: passing arg 1 of `XRefreshKeyboardMapping' from incompatible pointer type
hello.c:73: warning: passing arg 1 of `XLookupString' from incompatible pointer type
hello.c:79: warning: passing arg 2 of `XDestroyWindow' makes integer from pointer without a cast
Apparement les fonctions de bibliothèques renaclent sur les types d'arguments ?! Où est le problème ?