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
|
#include <stdlib.h>
#include <gtk/gtk.h>
void OnDestroy(GtkWidget *pWidget, gpointer pData);
void affiche (GtkWidget *pWidget, gpointer pData);
int main(int argc,char **argv)
{
/* Declaration du widget */
GtkWidget *pWindow;
GtkWidget *pTable;
GtkWidget *pButton;
GtkWidget *pFrame;
GtkWidget *pFrame1;
GtkWidget *pImage;
GtkWidget *pImage1;
GtkWidget *pImage2;
gtk_init(&argc,&argv);
/* Creation de la fenetre */
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*création de la table*/
pTable=gtk_table_new(3,2,TRUE);
gtk_container_add(GTK_CONTAINER(pWindow), GTK_WIDGET(pTable));
/*création de la frame*/
pFrame = gtk_frame_new("Service");
pFrame1 = gtk_frame_new("Lampe");
/*crétaion de l'image*/
pImage = gtk_image_new_from_file("./index.jpg");
pImage1 = gtk_image_new_from_file("./light-off.png");
pImage2 = gtk_image_new_from_file("./light-on.png");
/*création d'un bouton*/
pButton= gtk_button_new();
gtk_button_set_image(GTK_BUTTON(pButton),pImage);
void affiche (GtkWidget *pWidget, gpointer pData)
{
gtk_table_attach(GTK_TABLE(pTable), pImage1,
0, 1, 0, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL ,
0, 0);
}
gtk_table_attach(GTK_TABLE(pTable), pImage2,
0, 1, 0, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL ,
0, 0);
gtk_table_attach(GTK_TABLE(pTable), pFrame,
1, 2, 0, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL ,
0, 0);
gtk_table_attach(GTK_TABLE(pTable), pFrame1,
0, 1, 0, 3,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL ,
0, 0);
/* Insertion des boutons */
gtk_table_attach(GTK_TABLE(pTable), pButton,
1, 2, 2, 3,
GTK_EXPAND, GTK_EXPAND ,
0, 0);
/* Definition de la position */
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
/* Definition de la taille de la fenetre */
gtk_window_set_default_size(GTK_WINDOW(pWindow), 500, 320);
/* Titre de la fenetre */
gtk_window_set_title(GTK_WINDOW(pWindow), "Chapitre Fenetre");
/* Connexion du signal "destroy" */
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(OnDestroy), NULL);
g_signal_connect(G_OBJECT(pButton), "clicked", G_CALLBACK(affiche),NULL);
/* Affichage de la fenetre */
gtk_widget_show_all(pWindow);
/* Demarrage de la boucle evenementielle */
gtk_main();
return EXIT_SUCCESS;
}
void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
/* Arret de la boucle evenementielle */
gtk_main_quit();
} |
Partager