Re: [gtk-list] Re: Q: automatic function on program startup



In article <348BF58F.9AB5189@redestb.es>
eduperez@redestb.es writes:

> csmall@scooter.o.i.net wrote:
> > 
> > Eduardo Perez wrote:
> > > I need to write a program which shows a window when starting and then
> > > enters a function (that displays some info in that window), without any
> > > user interaction. Could anybody tell me if is this possible and how,
> > > please?
[snip]

Your need seems like the credit window which some commercial apprications show
at the beginning of execution.
Following code can do that. Is this fit your need?


#include <stdio.h>
#include <gtk/gtk.h>

void real_beginning (GtkWidget *widget, gpointer data)
{
  gint tag;
  GtkWidget *second, *button;

  tag = (gint) data;
  gtk_timeout_remove (tag);

  second = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW(second), "SECOND");

  button = gtk_button_new_with_label ("QUIT");
  gtk_container_add (GTK_CONTAINER(second), button);
  gtk_signal_connect (GTK_OBJECT(button), "clicked",
		      GTK_SIGNAL_FUNC(gtk_exit), 0),

  gtk_widget_show (button);
  gtk_widget_show (second);
}

gint timeout_func (gpointer data)
{
  GtkWidget *first = (GtkWidget *) data;

  gtk_widget_destroy (first);

  return FALSE;
}

int main (int argc, char **argv)
{
  GtkWidget *first, *button;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  first = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW(first), "FIRST");
  gtk_signal_connect (GTK_OBJECT(first), "destroy",
		      GTK_SIGNAL_FUNC (real_beginning), NULL);

  button = gtk_button_new_with_label ("CLOSE");
  gtk_container_add (GTK_CONTAINER(first), button);
  gtk_signal_connect_object (GTK_OBJECT(button), "clicked",
		      GTK_SIGNAL_FUNC(gtk_widget_destroy),
		      GTK_OBJECT(first));

  gtk_widget_show (button);
  gtk_widget_show (first);
  
  gtk_timeout_add (5000, timeout_func, first);

  gtk_main ();

  return 0;
}


                                  -Takashi Matsuda
                                   matsu@arch.comp.kyutech.ac.jp



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]