程序代码:
#include <gtk/gtk.h>
GdkPixbuf *creat_pixbuf(const gchar *file)
{
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_file(file, &error);
if (!pixbuf)
{
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
}
return pixbuf;
}
int main(int argc, char **argv)
{
/*定义一个窗口指针*/
GtkWidget *main_window;
/*初始化*/
gtk_init(&argc, &argv);
/*创建一个窗口*/
main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*设置窗口标题*/
gtk_window_set_title(GTK_WINDOW(main_window), "Yucoat!");
/*设置窗口默认大小*/
gtk_window_set_default_size(GTK_WINDOW(main_window), 280, 200);
/*设置窗口所在位置*/
gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
/*设置窗口图标*/
gtk_window_set_icon(GTK_WINDOW(main_window), creat_pixbuf("music.png"));
g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
/*显示窗口*/
gtk_widget_show(main_window);
gtk_main();
return 0;
}