[c]代码库
/**
* hellogtk.c
* gtk-3.0
*/
#include <gtk/gtk.h>
/* a callback function */
static void hello (GtkWidget *widget, gpointer data)
{
g_print ("%s\n", (char *)data);
}
int main (int argc, char* argv[])
{
/* first thing first */
gtk_init (&argc, &argv);
/* window object */
GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello, GTK!");
gtk_widget_set_size_request (window, 320, 200);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS);
g_signal_connect (G_OBJECT (window), "delete_event",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
/* a container */
GtkWidget *box = gtk_box_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show (box);
/* two buttons */
GtkWidget *button1, *button2;
button1 = gtk_button_new_with_label ("Hello, World!");
g_signal_connect (button1, "clicked", G_CALLBACK(hello), "Hello, World!");
gtk_box_pack_start(GTK_BOX (box), button1, TRUE, FALSE, 0);
gtk_widget_show (button1);
button2 = gtk_button_new_with_label ("Hello, GTK!");
g_signal_connect (button2, "clicked", G_CALLBACK(hello), "Hello, GTK!");
gtk_box_pack_start (GTK_BOX (box), button2, TRUE, FALSE, 0);
gtk_widget_show (button2);
/* main loop start */
gtk_main ();
return 0;
}
[代码运行效果截图]
[源代码打包下载]
by: 发表于:2017-06-20 16:13:02 顶(0) | 踩(0) 回复
??
回复评论