6.2.1 サンプルプログラムの全体


// コールバック関数を使うための準備
#include "modclbk.as"
    newclbk3 cb_win_delete_event, 3, *on_win_delete_event, CLBKMODE_CDECL@

// GTK+の関数を使うための準備
#uselib "libgtk-3-0.dll"
#func global gtk_init "gtk_init" sptr, sptr
#func global gtk_window_new "gtk_window_new" int
#func global gtk_table_new "gtk_table_new" int, int, int
#func global gtk_table_set_col_spacings "gtk_table_set_col_spacings" sptr, int
#func global gtk_table_set_row_spacings "gtk_table_set_row_spacings" sptr, int
#func global gtk_table_attach_defaults "gtk_table_attach_defaults" sptr, sptr, int, int, int, int
#func global gtk_button_new_with_label "gtk_button_new_with_label" sptr
#func global gtk_container_add "gtk_container_add" sptr, sptr
#func global gtk_widget_show_all "gtk_widget_show_all" sptr
#func global gtk_main "gtk_main"
#func global gtk_main_quit "gtk_main_quit"

#uselib "libgobject-2.0-0.dll"
#define g_signal_connect(%1, %2, %3, %4) g_signal_connect_data %1, %2, %3, %4, 0, 0
#func global g_signal_connect_data "g_signal_connect_data" sptr, str, sptr, sptr, int, int

// よく使う定数
; ヌルポインタ
#const NULL 0
; 真偽値
#const TRUE 1

    // GTK+初期化
    gtk_init NULL, NULL

    // ウィンドウ生成
#const GTK_WINDOW_TOPLEVEL 0 ; GtkWindowType
    gtk_window_new GTK_WINDOW_TOPLEVEL
    win = stat
    g_signal_connect win, "delete-event", cb_win_delete_event, NULL

    // テーブル生成
    gtk_table_new 3, 3, TRUE
    tbl = stat
    gtk_table_set_col_spacings tbl, 10
    gtk_table_set_row_spacings tbl, 10

    // ボタン群生成
    gtk_button_new_with_label "Button 1"
    btn1 = stat
    gtk_button_new_with_label "Button 2"
    btn2 = stat
    gtk_button_new_with_label "Button 3"
    btn3 = stat
    gtk_button_new_with_label "Button 4"
    btn4 = stat
    gtk_button_new_with_label "Button 5"
    btn5 = stat
    gtk_button_new_with_label "Button 6"
    btn6 = stat

    // ウィンドウの組み立て
    gtk_table_attach_defaults tbl, btn1, 0, 1, 0, 1
    gtk_table_attach_defaults tbl, btn2, 1, 3, 0, 1
    gtk_table_attach_defaults tbl, btn3, 0, 1, 1, 3
    gtk_table_attach_defaults tbl, btn4, 1, 3, 1, 2
    gtk_table_attach_defaults tbl, btn5, 1, 2, 2, 3
    gtk_table_attach_defaults tbl, btn6, 2, 3, 2, 3
    gtk_container_add win, tbl

    // ウィンドウの表示とメインループの開始
    gtk_widget_show_all win
    gtk_main
    end

/* シグナルハンドラ */
*on_win_delete_event
    gtk_main_quit
    return

Prev - Table of contents - Next