gtk-sandbox/gtk3/icon/exampleapp.c

55 lines
1.2 KiB
C

#include <gtk/gtk.h>
GdkPixbuf *create_pixbuf(const gchar * filename) {
//TODO This is not working with pointers!
g_print("create_pixbuf() filename: %d\n", filename);
GdkPixbuf *pixbuf;
GError *error = NULL;
/*create pixbuf by loading an image from a file*/
pixbuf = gdk_pixbuf_new_from_file(filename, &error);
if (!pixbuf) {
/*print error msg if icon can not be loaded*/
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
}
return pixbuf;
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GdkPixbuf *icon;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Icon");
gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
/*create GdkPixbuf from a PNG file*/
icon = create_pixbuf("Logo_SIB_electricindigo.png");
/*display an icon*/
gtk_window_set_icon(GTK_WINDOW(window), icon);
/*flag the widget to be displayed*/
gtk_widget_show(window);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
/*decrease the reference count of the pixbuf object*/
g_object_unref(icon);
gtk_main();
return 0;
}