直接显示一个空白窗口,代码hello.c如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* compile command:
gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`
*/


#include <gtk/gtk.h>

int main( int argc, char *argv[])
{

GtkWidget* window;
GtkWidget* frame;
GtkWidget* label;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

gtk_window_set_title(GTK_WINDOW(window), "Hello World");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), frame);

label = gtk_label_new("Hello World");
gtk_fixed_put(GTK_FIXED(frame), label, 10, 10);

g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);
gtk_main();

return 0;
}

知识共享授权条款
本著作Chen, Zai-Chun制作,以知识共享 姓名标示-相同方式分享 4.0 国际 授权条款释出

留言

Sep 15 2010