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
| #include <stdlib.h>
#include <gtk/gtk.h>
void OnButton(GtkWidget *pWidget, gpointer data);
GtkWidget *pMin;
GtkWidget *pMax;
GtkWidget *pEncours;
int main(int argc,char **argv)
{
GtkWidget* pWindow;
GtkWidget *pMainVBox;
GtkWidget *pProgress;
GtkWidget *pButton;
gtk_init(&argc,&argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(pWindow), "GtkProgressBar");
gtk_window_set_default_size(GTK_WINDOW(pWindow), 320, 200);
gtk_container_set_border_width(GTK_CONTAINER(pWindow), 4);
pMainVBox = gtk_vbox_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(pWindow), pMainVBox);
/* Creation du GtkEntry */
pMin = gtk_entry_new();
/* Insertion du GtkEntry dans la GtkVBox */
gtk_box_pack_start(GTK_BOX(pMainVBox), pMin, TRUE, FALSE, 0);
/* Creation du GtkEntry */
pMax = gtk_entry_new();
/* Insertion du GtkEntry dans la GtkVBox */
gtk_box_pack_start(GTK_BOX(pMainVBox), pMax, TRUE, FALSE, 0);
pEncours = gtk_entry_new();
/* Insertion du GtkEntry dans la GtkVBox */
gtk_box_pack_start(GTK_BOX(pMainVBox), pEncours, TRUE, FALSE, 0);
/* Creation de la barre de progression */
pProgress = gtk_progress_bar_new();
gtk_box_pack_start(GTK_BOX(pMainVBox), pProgress, TRUE, FALSE, 0);
pButton = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
gtk_box_pack_start(GTK_BOX(pMainVBox), pButton, TRUE, FALSE, 0);
g_signal_connect_swapped(G_OBJECT(pButton), "clicked", G_CALLBACK(OnButton), pProgress);
gtk_widget_show_all(pWindow);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
return EXIT_SUCCESS;
}
void OnButton(GtkWidget *pWidget, gpointer data)
{
double max;
double min;
double Encours;
double Val1;
double Diff;
max=atof(gtk_entry_get_text(GTK_ENTRY(pMax)));
min=atof(gtk_entry_get_text(GTK_ENTRY(pMin)));
Diff = max - min;
Encours = atof(gtk_entry_get_text(GTK_ENTRY(pEncours)));
Val1=(Encours-min)/Diff;
g_print("%f\n",min);
g_print("%f\n",max);
g_print("%f\n",Encours);
g_print("%f\n",Diff);
g_print("%f\n",Val1);
/* Initialisation */
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pWidget), Val1);
} |
Partager