compile by : cc -o d_box -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/X11R6/include -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXi -lXext -lX11 -lm d_box.c
#include <stdio.h>
#include <gtk/gtk.h>
void ButtonClicked(GtkWidget *widget, gpointer data);
int main(int argc, char *argv[])
{
GtkWidget *window, *yes, *no, *basebox, *hbox, *tbox;
GtkWidget *lbox;
char mesg[512];
if (argc != 2)
{
fprintf(stderr,"Usage : %s\n",argv[0]);
exit(-1);
}
gtk_set_locale();
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"Dialog box test");
gtk_window_set_default_size(GTK_WINDOW(window),400,100);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
basebox = gtk_vbox_new(TRUE,0);
hbox = gtk_hbox_new(TRUE,0);
gtk_box_pack_start(GTK_BOX(basebox), hbox, FALSE, TRUE, 0);
tbox = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(basebox), tbox, FALSE, TRUE, 0);
sprintf(mesg,"%s",argv[1]);
lbox = gtk_label_new(mesg);
gtk_box_pack_start(GTK_BOX(hbox), lbox, FALSE, TRUE, 0);
gtk_button_box_set_layout(GTK_BUTTON_BOX(tbox),GTK_BUTTONBOX_SPREAD);
gtk_button_box_set_child_size(GTK_BUTTON_BOX(tbox),50,16);
yes = gtk_button_new_with_label("Yes");
gtk_container_add(GTK_CONTAINER(tbox), yes);
gtk_signal_connect(GTK_OBJECT(yes), "clicked", GTK_SIGNAL_FUNC(ButtonClicked), "yes");
no = gtk_button_new_with_label("No");
gtk_container_add(GTK_CONTAINER(tbox), no);
gtk_signal_connect(GTK_OBJECT(no), "clicked", GTK_SIGNAL_FUNC(ButtonClicked), "no");
gtk_container_add(GTK_CONTAINER(window), basebox);
gtk_window_set_focus(GTK_WINDOW(window),yes);
gtk_widget_show_all(window);
gtk_main();
return(0);
}
void ButtonClicked(GtkWidget *widget, gpointer data)
{
if (g_strcasecmp(data, "yes") == 0)
{
printf("0\n");
}
else
{
printf("1\n");
}
gtk_main_quit();
}
沒有留言:
張貼留言