/* * Thought process in creating/modifying this program I used EventOne and EventTwo * EventOne is used to tell how often & when timeout_cb is to be called and within * timeout_cb() EventTwo should tell when the display disappears automatically if * user has not killed the display with the OK button. * Killing the display with the button works fine but the timeout does not. */ #include //#include #include #include GtkWidget *dialog; gint Count; guint Event, EventOne, EventTwo; void response_cb( GtkDialog *dialog ) { if (EventTwo) g_source_remove(EventTwo); gtk_widget_destroy( GTK_WIDGET( dialog ) ); } gboolean timeout_cb() { struct tm *tm_ptr; time_t the_time; gchar Message[256]; time(&the_time); tm_ptr = localtime(&the_time); g_sprintf(Message,"%d It is now %02d:%02d:%02d\n", Count++, tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec); dialog = gtk_message_dialog_new( NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, Message ); g_signal_connect( G_OBJECT( dialog ), "response", G_CALLBACK( response_cb ), dialog ); gtk_widget_show( dialog ); if (EventTwo) { g_source_remove(EventTwo); EventTwo = g_timeout_add(11000, (GSourceFunc) response_cb, NULL); } return( TRUE ); } int main( int argc, char **argv ) { gtk_init (&argc, &argv); Count = 1; EventOne = g_timeout_add(10000, (GSourceFunc) timeout_cb, NULL ); gtk_main(); return( 0 ); }