gtkのインストール
~$ su;パスワードを入力し管理者権限になる
# aptitude install libgtk2.0-dev
ウインドウにhelloworldを表示させる
-----------gtkhelloworld.c-------------
#include
gboolean
cb_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
GdkWindow *drawable = widget->window;
cairo_t *cr;
cr = gdk_cairo_create (drawable);
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
cairo_select_font_face (cr, "FreeSans",
CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 40.0);
cairo_move_to (cr, 50.0, 50.0);
cairo_show_text (cr, "Hello,World");
cairo_destroy (cr);
return FALSE;
}
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *canvas;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), "Hello World");
gtk_widget_set_size_request (window, 400, 200);
g_signal_connect (G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
canvas = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER(window), canvas);
g_signal_connect (G_OBJECT(canvas), "expose_event",
G_CALLBACK (cb_expose_event), NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
---------------------------------------
gtkhelloworld.cのダウンロード
(cdコマンドでgtkhelloworld.cの置いてあるディレクトリに移動しておく)
~$ gcc gtkhelloworld.c -o gtkhelloworld `pkg-config --cflags --libs gtk+-2.0`
~$ ./gtkhelloworld