#include <gtk/gtk.h>typedef struct _ProgressData { GtkWidget *window; GtkWidget *pbar; GtkWidget *vbox; GtkWidget *image; GtkWidget *align; int timer; }ProgressData;typedef struct _MainData { GtkWidget *MainWin;}MainData;MainData *pmdata;
Static void destroy_progress (GtkWidget * widget, ProgressData * pdata);/* update the progress bar to see the movement of the progress bar */static gint progress_timeout (gpointer data) {ProgressData * pdata = (ProgressData *) data; gdouble new_val; /* calculate the progress bar value using the value range set in the adjustment object */new_val = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pdata-> pbar) + 0.05; if (new_val> 1.0) {// new_val = 0.0;/* perform other operations after the progress bar is 100% */gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata-> pbar), 1.0); g_usleep (500 ); destroy_progress (pdata-> pbar, pdata); return FALSE;}/* set the new value of the progress bar */gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata-> pbar), new_val ); /* This is a timeout function, and returns TRUE, so that it can continue to be called */Int main (INT argc, char * argv []) {progressdata * pdata = NULL; gtk_init (& argc, & argv ); /* allocate memory for the data passed to the callback function */pdata = g_malloc (sizeof (progressdata); pmdata = g_malloc (sizeof (maindata )); pdata-> window = gtk_window_new (gtk_window_popup); gtk_window_set_resizable (gtk_window (pdata-> window), false);/* do not connect to the gtk_main_quit callback, in this way, destroy the Splash window safely * // g_signal_connect (g_object (pdata-> window), "Destroy", g_callback (gtk_main_quit), null ); gtk_window_set_position (gtk_window (pdata-> window), gtk_win_pos_center_always); gtk_widget_set_size_request (pdata-> window, 500,350 ); /* Main Window will display after Splash window */pmdata-> mainwin = gtk_window_new (gtk_window_toplevel); gtk_window_set_resizable (gtk_window (pmdata-> mainwin), false ); g_signal_connect (g_object (pmdata-> mainwin), "Destroy", g_callback (gtk_main_quit), null); gtk_window_set_position (gtk_window (pmdata-> mainwin), callback ); gtk_widget_set_size_request (pmdata-> mainwin, 500,500);/* vbox for layout Splash window */pdata-> vbox = gtk_vbox_new (false, 5 ); struct (gtk_container (pdata-> vbox), 0); gtk_container_add (gtk_container (pdata-> window), pdata-> vbox); gtk_widget_show (pdata-> vbox ); /* image */pdata-> image = gtk_image_new_from_file ("image/splash.png"); gtk_box_pack_start (gtk_box (pdata-> vbox), pdata-> image, true, 0); gtk_widget_show (pdata-> image);/* create a center-aligned object */pdata-> align = gtk_alignment_new (0.5, 1, 1, 1 ); gtk_box_pack_start (gtk_box (pdata-> vbox), pdata-> align, false, false, 0); gtk_widget_show (pdata-> align ); /* create progress bar */pdata-> pbar = gtk_progress_bar_new (); gtk_container_add (gtk_container (pdata-> align), pdata-> pbar); gtk_widget_show (pdata-> pbar ); /* Add a timer (timer) to update the progress bar value */pdata-> timer = gtk_timeout_add (100, progress_timeout, pdata); gtk_widget_show (pdata-> window ); // gtk_widget_show (pdata-> mainwin); gtk_main (); Return 0 ;}
Return TRUE;}/* clears the allocated memory, deletes the timer (timer), and calls the function when the progress bar is full. It can be used to do many things */static void destroy_progress (GtkWidget * widget, progressData * pdata) {gtk_timeout_remove (pdata-> timer); pdata-> timer = 0; gtk_widget_destroy (pdata-> pbar); gtk_widget_destroy (pdata-> image ); // gtk_widget_hide (pdata-> window );
Gtk_widget_destroy (pdata-> window); g_free (pdata); gtk_widget_show (pmdata-> MainWin );}