Bonjour.

J'ai récupéré un code sur Wikibooks à propos des placements.
Le soucis, c'est que j'ai une erreur à l'exécution et je trouve ça un peu bizarre pour un code qui est sur le wiki...

Voici le code

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "gtk/gtk.h"
 
void
delete_event (GtkWidget *widget, GdkEvent *event, gpointer *data)
{
    gtk_main_quit ();
} 
 
/* Construction d'une nouvelle hbox remplie de boutons. Les paramètres qui 
 * nous intéressent sont passés à cette fonction.
 * On n'affiche pas la boîte, mais tout ce qu'elle contient. */
 
GtkWidget *make_box (gint homogeneous, gint spacing,
                    gint expand, gint fill, gint padding) 
{
    GtkWidget *box;
    GtkWidget *button;
    char padstr[80];
 
    /* Création d'une hbox avec les paramètres homogeneous et spacing
     * voulus. */
 
    box = gtk_hbox_new (homogeneous, spacing);
 
    /* Création d'une série de boutons configurés de façon appropriée */
 
    button = gtk_button_new_with_label ("gtk_box_pack");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    button = gtk_button_new_with_label ("(box,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    button = gtk_button_new_with_label ("button,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    /* Création d'un bouton portant un label dépendant de la valeur
     * du paramètre expand. */
 
    if (expand == TRUE)
            button = gtk_button_new_with_label ("TRUE,");
    else
            button = gtk_button_new_with_label ("FALSE,");
 
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    /* Même chose que ci-dessus mais sous forme abrégée. */
 
    button = gtk_button_new_with_label (fill ? "TRUE," : "FALSE,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    /* Récupération du paramètre padding sous forme de chaîne. */
 
    sprintf (padstr, "%d);", padding);
 
    button = gtk_button_new_with_label (padstr);
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);
 
    return box;
}
 
int main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *box1;
    GtkWidget *box2;
    GtkWidget *separator;
    GtkWidget *label;
    GtkWidget *quitbox;
    int which;
 
    /* Initialisation, à ne jamais oublier ! :) */
 
    gtk_init (&argc, &argv);
 
    if (argc != 2) {
        fprintf (stderr, "usage : %s num, où num vaut 1, 2, ou 3.\n", *argv);
 
        /* Nettoyage dans GTK et sortie avec un code d'erreur de 1 */
      gtk_exit (1);
    }
 
    which = atoi (argv[1]);
 
    /* Création de notre fenêtre. */
 
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
    /* Il ne faut jamais oublier de connecter le signal "destroy" à la
     * fenêtre principale. C'est très important pour disposer d'un 
     * comportement intuitif adéquat. */
 
    gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                        GTK_SIGNAL_FUNC (delete_event), NULL);
 
    gtk_container_border_width (GTK_CONTAINER (window), 10);
 
 
    /* Création d'une boîte verticale (vbox) pour y placer les boîtes
     * horizontales.
     * Ceci permet de placer les boîtes horizontales contenant les boutons
     * les unes au dessus des autres dans cette vbox. */
 
    box1 = gtk_vbox_new (FALSE, 0);
 
    /* L'exemple à afficher. Ils correspondent aux images ci-dessus. */
 
    switch (which) {
    case 1:
        /* Création d'un label. */
 
        label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
 
        /* Alignement du label à gauche.  On précisera cette fonction ainsi
         * que les autres dans la section sur les attributs des widgets. */
 
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
        /* Placement du label dans la boîte verticale (vbox box1). Il ne
         * faut pas oublier que les widgets qui s'ajoutent à une vbox sont
         * placés les uns au dessus des autres. */
 
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
 
        /* Affichage du label */
 
        gtk_widget_show (label);
 
        /* On appelle notre fonction de construction de boîte :
         * homogeneous = FALSE, spacing = 0,
         * expand = FALSE, fill = FALSE, padding = 0 */
 
        box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* On appelle notre fonction de construction de boîte :
         * homogeneous = FALSE, spacing = 0,
         * expand = FALSE, fill = FALSE, padding = 0 */
 
        box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Paramètres : homogeneous = FALSE, spacing = 0, 
         * expand = TRUE, fill = TRUE, padding = 0 */
 
        box2 = make_box (FALSE, 0, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Création d'un séparateur, on verra cela plus tard, mais ils sont
         * simples à utiliser. */
 
        separator = gtk_hseparator_new ();
 
        /* Placement du séparateur dans la vbox. Ne pas oublier que tous les
         * widgets sont placés dans une vbox et qu'il seront placés 
         * verticalement. */
 
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
        gtk_widget_show (separator);
 
        /* Création d'un nouveau label et affichage de celui-ci. */
 
        label = gtk_label_new ("gtk_hbox_new (TRUE, 0);");
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
 
        /* Paramètres : homogeneous = TRUE, spacing = 0, 
         * expand = TRUE, fill = FALSE, padding = 0 */
 
        box2 = make_box (TRUE, 0, TRUE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Paramètres : homogeneous = TRUE, spacing = 0, 
         * expand = TRUE, fill = TRUE, padding = 0 */
 
        box2 = make_box (TRUE, 0, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Un autre séparateur */
 
        separator = gtk_hseparator_new ();
 
        /* Les 3 derniers paramètres de gtk_box_pack_start sont : 
         * expand = FALSE, fill = TRUE, padding = 5. */
 
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
        gtk_widget_show (separator);
 
        break;
 
    case 2:
 
        /* Création d'un label, box1 est une vbox identique à 
         * celle créée au début de main() */
 
        label = gtk_label_new ("gtk_hbox_new (FALSE, 10);");
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
 
        /* Paramètres : homogeneous = FALSE, spacing = 10, 
         * expand = TRUE, fill = FALSE, padding = 0 */
 
        box2 = make_box (FALSE, 10, TRUE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Paramètres : homogeneous = FALSE, spacing = 10, 
         * expand = TRUE, fill = TRUE, padding = 0 */
 
        box2 = make_box (FALSE, 10, TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        separator = gtk_hseparator_new ();
 
        /* Les 3 derniers paramètres de gtk_box_pack_start sont : 
         * expand = FALSE, fill = TRUE, padding = 5. */
 
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
        gtk_widget_show (separator);
 
        label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
        gtk_widget_show (label);
 
        /* Paramètres : homogeneous = FALSE, spacing = 0, 
         * expand = TRUE, fill = FALSE, padding = 10 */
 
        box2 = make_box (FALSE, 0, TRUE, FALSE, 10);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Paramètres : homogeneous = FALSE, spacing = 0, 
         * expand = TRUE, fill = TRUE, padding = 10 */
 
        box2 = make_box (FALSE, 0, TRUE, TRUE, 10);
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        separator = gtk_hseparator_new ();
 
        /* Les 3 derniers paramètres de gtk_box_pack_start sont : 
         * expand = FALSE, fill = TRUE, padding = 5. */
 
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
        gtk_widget_show (separator);
        break;
 
    case 3:
 
        /* Ceci est une démonstration de la possibilité d'utiliser 
         * gtk_box_pack_end() pour aligner les widgets à droite.
         * On crée d'abord une nouvelle boîte comme d'habitude. */
 
        box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
 
        /* On crée le label qui sera mis à la fin. */
 
        label = gtk_label_new ("end");
 
        /* On le place en utilisant gtk_box_pack_end(), il est ainsi
         * mis à droite de la hbox créée par l'appel à make_box(). */
 
        gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0);
 
        /* Affichage du label. */
 
        gtk_widget_show (label);
 
        /* Placement de box2 dans box1 (la vbox, vous vous rappelez ? :) */
 
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
        gtk_widget_show (box2);
 
        /* Séparateur pour le bas. */
 
        separator = gtk_hseparator_new ();
 
        /* Configuration du séparateur en 400x5 pixels. 
         * La hbox que l'on a créée aura donc 400 pixels de large, 
         * et le label "end" sera séparé des autres de la hbox.
         * Sinon, tous les widgets de la hbox seraient placés les plus
         * près possible les uns des autres. */
 
        gtk_widget_set_usize (separator, 400, 5);
 
        /* Placement du séparateur dans la vbox (box1) 
         * créée au debut de main(). */
 
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
        gtk_widget_show (separator);    
    }
 
    /* Création d'une nouvelle hbox.. vous pouvez en utiliser autant que
     * que vous en avez besoin ! */
 
    quitbox = gtk_hbox_new (FALSE, 0);
 
    /* Notre bouton pour quitter. */
 
    button = gtk_button_new_with_label ("Quit");
 
    /* Configuration du signal pour détruire la fenêtre. Ceci enverra le
     * signal "destroy" à la fenêtre. Ce signal sera à son tour capturé
     * par notre gestionnaire de signal défini plus haut. */
 
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
                               GTK_SIGNAL_FUNC (gtk_widget_destroy),
                               GTK_OBJECT (window));
 
    /* Placement du bouton dans la « quitbox ».
     * Les 3 derniers paramètres de gtk_box_pack_start sont : 
     * expand = TRUE, fill = FALSE, padding = 0. */
 
    gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
 
    /* Placement de la quitbox dans la vbox (box1) */
 
    gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
 
    /* Placement de la vbox (box1), qui contient maintenant tous nos
     * widgets, dans la fenêtre principale. */
 
    gtk_container_add (GTK_CONTAINER (window), box1);
 
    /* Affichage */
 
    gtk_widget_show (button);
    gtk_widget_show (quitbox);
 
    gtk_widget_show (box1);
 
    /* Affichage de la fenêtre en dernier */
 
    gtk_widget_show (window);
 
    /* Ne pas oublier notre fonction principale. */
 
    gtk_main ();
 
    /* Le contrôle revient ici lorsque gtk_main_quit() est appelée,
     * jusqu'à ce que  gtk_exit() soitutilisée. */
 
    return 0;
}
Et voici ce que me dit ma charmante console à l'exécution :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
usage : ./WIKIBOOK1 num, où num vaut 1, 2, ou 3.
Une idée d'ou ca peut venir?