人間夜行

一切の有為の法 夢幻泡影の如し

GTK+ 03 icon

| 评论

对应http://zetcode.com/tutorials/gtktutorial/chinese/firstprograms/

#include <gtk/gtk.h>
//编译使用:gcc 文件名 `pkg-config --libs --cflags gtk+-2.0`
//所有注释仅为我的理解

//实现对图片的访问。目前不甚理解。大概是读入缓冲。
GdkPixbuf *create_pixbuf(const gchar * filename)
{ GdkPixbuf *pixbuf;
GError *error=NULL;
pixbuf=gdk_pixbuf_new_from_file(filename,&error);
if(!pixbuf)
{
fprintf(stderr,"%s\n",error->message);
g_error_free(error);
}
return pixbuf;
} int main( int argc, char *argv[])
{ GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"This is the TITLE");
gtk_window_set_default_size(GTK_WINDOW(window),400,300);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
//设置图标
gtk_window_set_icon(GTK_WINDOW(window),create_pixbuf("ra3.jpg"));
gtk_widget_show(window);
g_signal_connect_swapped(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
gtk_main();
return 0;
}

评论