Emmanuel Delahaye C is a sharp tool | exeed a écrit :
Cependant j'ai des problèmes de types je pense car je suis obligé de passer des éléments de structure aux fonctions callback et je ne pense pas que j'ai la bonne méthode.
|
Tu te compliques horriblement et évidemment, ça fini par être faux... Il faut rester simple :
Code :
- #include <stdlib.h>
- #include <gtk/gtk.h>
- #include <stdio.h>
- #include <time.h>
- typedef struct test
- {
- int tempsini;
- int tempsfin;
- GtkWidget *monwidget;
- }
- Test;
- void start_clock (GtkWidget * pWidget, gpointer pData)
- {
- struct test *ptest = pData;
- if (ptest != NULL)
- {
- ptest->tempsini = clock ();
- printf ("%d\n", ptest->tempsini);
- }
- }
- void stop_clock (GtkWidget * pWidget, gpointer pData)
- {
- struct test *ptest = pData;
- if (ptest != NULL)
- {
- ptest->tempsfin = clock ();
- printf ("%d\n", ptest->tempsfin);
- }
- }
- void resultat (GtkWidget * pWidget, gpointer pData)
- {
- struct test *ptest = pData;
- if (ptest != NULL)
- {
- int final = (ptest->tempsfin - ptest->tempsini);
- gtk_label_set_text (GTK_LABEL (ptest->monwidget), "youpi fete" );
- printf ("tempsfin %d\n", ptest->tempsfin);
- printf ("tempsini %d\n", ptest->tempsini);
- printf ("Difference %d\n", final);
- }
- }
- int main (int argc, char **argv)
- {
- GtkWidget *pWindow;
- GtkWidget *pVbox;
- GtkWidget *pHbox;
- GtkWidget *pButtons[3];
- Test test;
- gtk_init (&argc, &argv);
- pWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (G_OBJECT (pWindow), "destroy",
- G_CALLBACK (gtk_main_quit), NULL);
- gtk_window_set_title (GTK_WINDOW (pWindow), "Les GtkBox" );
- gtk_window_set_default_size (GTK_WINDOW (pWindow), 320, 200);
- pVbox = gtk_vbox_new (TRUE, 0);
- gtk_container_add (GTK_CONTAINER (pWindow), pVbox);
- test.monwidget = gtk_label_new ("Temps passe= Rien" );
- pButtons[0] = gtk_button_new_with_label ("Depart" );
- pButtons[1] = gtk_button_new_with_label ("Arret" );
- pButtons[2] = gtk_button_new_with_label ("Resultat" );
- g_signal_connect (G_OBJECT (pButtons[0]), "clicked",
- G_CALLBACK (start_clock), (&test));
- g_signal_connect (G_OBJECT (pButtons[1]), "clicked",
- G_CALLBACK (stop_clock), (&test));
- g_signal_connect (G_OBJECT (pButtons[2]), "clicked", G_CALLBACK (resultat),
- &test);
- gtk_box_pack_start (GTK_BOX (pVbox), pButtons[0], TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (pVbox), pButtons[1], TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (pVbox), pButtons[2], TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (pVbox), test.monwidget, TRUE, TRUE, 0);
- gtk_widget_show_all (pWindow);
- gtk_main ();
- return 0;
- }
|
2296
4062
tempsfin 4062
tempsini 2296
Difference 1766
Press ENTER to continue.
|
Pose des questions si tu ne comprends pas.
---------------
Des infos sur la programmation et le langage C: http://www.bien-programmer.fr Pas de Wi-Fi à la maison : http://www.cpl-france.org/
|