Add GTK+ example

This commit is contained in:
Juraj Michalek
2012-11-25 18:05:51 +01:00
parent 7a75ba2b50
commit 2f8a23729c
2 changed files with 56 additions and 0 deletions

14
gtk/Makefile Normal file
View File

@@ -0,0 +1,14 @@
PACKAGE = helloworld
OBJECTS = helloworld.o
CFLAGS = `pkg-config --cflags gtk+-3.0`
LDADD = `pkg-config --libs gtk+-3.0`
helloworld: $(OBJECTS)
${CC} -o ${PACKAGE} ${OBJECTS} ${LDADD}
.c.o:
${CC} ${CFLAGS} -c $<
clean:
rm -f helloworld *.o

42
gtk/helloworld.c Normal file
View File

@@ -0,0 +1,42 @@
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
gtk_init(&argc, &argv);
/* Create the main, top level window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* Give it the title */
gtk_window_set_title(GTK_WINDOW(window), "Hello, world!");
/*
** Map the destroy signal of the window to gtk_main_quit;
** When the window is about to be destroyed, we get a notification and
** stop the main GTK+ loop by returning 0
*/
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
/*
** Assign the variable "label" to a new GTK label,
** with the text "Hello, world!"
*/
label = gtk_label_new("Hello, world!");
/* Plot the label onto the main window */
gtk_container_add(GTK_CONTAINER(window), label);
/* Make sure that everything, window and label, are visible */
gtk_widget_show_all(window);
/*
** Start the main loop, and do nothing (block) until
** the application is closed
*/
gtk_main();
return 0;
}