Re: Signals & Callbacks - Help!! Part 2



jalkadir gosonic ca ha scritto lo scorso 09/07/2005 02:28:
Thank Yeti for your help, I really appreciate your input. However, due to
my lack of experience on GTK+ I am afraid I would need something a bit
more tangible. Could you please provide me with a example or point me to
to a place where I could find examples of GTK+ software?

Thanks in advance.

Maybe this can help you.
Cheers,
Carlo

#include <gtk/gtk.h>

void on_btn_clicked (GtkButton *, gpointer);

int main (int argc, char *argv[])
{
  GtkWidget *mainw;
  GtkWidget *vbox;
  GtkWidget *btn;
  gchar     *text;

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

  /* a very simple window with a button
   */
  mainw = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (mainw, 400, -1);
  gtk_window_set_title (GTK_WINDOW (mainw), "main");
  gtk_window_set_position (GTK_WINDOW (mainw), GTK_WIN_POS_CENTER);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (mainw), vbox);

  btn = gtk_button_new_with_mnemonic ("Click me");
  gtk_widget_show (btn);
  gtk_box_pack_start (GTK_BOX (vbox), btn, FALSE, FALSE, 0);

  g_signal_connect ((gpointer) mainw, "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);
  /* here is your text
   */
  text = g_strdup ("your text");
  g_signal_connect ((gpointer) btn, "clicked",
                    G_CALLBACK (on_btn_clicked),
                    (gpointer)text);

  gtk_widget_show (mainw);

  gtk_main ();

  /* not really needed, because we are quitting here
   */
  g_free (text);

  return 0;
}

void on_btn_clicked (GtkButton *btn, gpointer your_data)
{
  g_print ("%s\n", (gchar *)your_data);
}



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