Don't know why this does not work.
- From: Bill Shui <wshui mail usyd edu au>
- To: gtk-list redhat com
- Subject: Don't know why this does not work.
- Date: Sun, 09 Jan 2000 19:18:44 +1100
Hi All,
the following is my first attempt to write a hello world program using
gtk.
#include <gtk/gtk.h>
gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_print("This Event is to be deleted\n");
return (TRUE);
}
void destroy(GtkWidget *widget, gpointer data)
{
if (data != NULL)
g_print("%s\n", (char *) data);
gtk_main_quit();
}
void hello(GtkWidget *widget, GdkEvent *event, gpointer data)
{
if (data != NULL)
g_print("%s was pressed.\n", (char *) data);
else
g_print ("Hellow World!\n");
}
void crap(GtkWidget *widget, GdkEvent *event, gpointer data)
{
if (data != NULL)
{
g_print("%s was pressed", (char *) data);
}
else
g_print ("Crap!!!\n");
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
guint gi;
GtkWidget *window, *box1;
GtkWidget * button1, * button2, *button3;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 40);
gtk_window_set_title(GTK_WINDOW(window), "My Test Program");
button1 = gtk_button_new_with_label("Hello Button");
button2 = gtk_button_new_with_label("Crap Button");
button3 = gtk_button_new_with_label("Quit");
box1 = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), box1);
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(delete_event), NULL);
gtk_signal_connect(GTK_OBJECT(button1), "clicked",
GTK_SIGNAL_FUNC(hello), (gpointer) "Hello
Button");
gtk_signal_connect(GTK_OBJECT(button2), "clicked",
GTK_SIGNAL_FUNC(crap), (gpointer) "Crap
Button");
gtk_signal_connect(GTK_OBJECT(button3), "clicked",
GTK_SIGNAL_FUNC(destroy), (gpointer)
"Quitting");
gtk_box_pack_start(GTK_BOX(box1), button1, TRUE, TRUE, 0);
gtk_widget_show(button1);
gtk_box_pack_start(GTK_BOX(box1), button2, TRUE, TRUE, 0);
gtk_widget_show(button2);
gtk_box_pack_start(GTK_BOX(box1), button3, TRUE, TRUE, 0);
gtk_widget_show(button3);
gtk_widget_show(box1);
gtk_widget_show(window);
gtk_main();
return (0);
}
-------------------------------------------------
I've compiled it and ran the program.
it seemed to work, however, when I click on "crap" or "hello" button.
I get something like these printed out in my terminal:
¸ct@\ was pressed <--- it should print "crap button was pressed"
pct was pressed. <-- it should print "hello button was pressed"
so I"m just curious how g_print should be done properly.
Ps I used "g++ -g -lgtk -lgdk -lglib -o test test.cpp"
command to compile the program.
thanks for the help.
cheers.
--
-----------------------------------------------------------------------
Bill Shui eBioinformatics
Trainee Bioinformatics Programmer Bay 16/104
email: bill.shui@eBioinformatics.com Australian Technology Park
ph: +61 (2) 9209-4765 Eveleigh 1430, NSW, Australia.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]