Cè¨èªã§GTK+ 2ãæ±ãä¸ã§ã®å¹¾ã¤ãã®ã¡ã¢(第2å)
ãC言語でGTK+ 2を扱う上での幾つかのメモ(第1回)ãã®ç¶ãã
åºæ¬çãªå½¢
ç¨ããããããã¡ã¤ã«
ããããã¡ã¤ã«ã¯gtk/gtk.hãåç §ãããGTK+ 2ã§ã¯GLib 2ã®é¢æ°(ãg_ãã§å§ã¾ãååã®é¢æ°)ãç¨ãããã¨ãå¤ãããGLib 2ã®ããããã¡ã¤ã«(glib/glib.h)ã¯ããã°ã©ã ããç´æ¥åç §ããå¿ è¦ã¯ãªãã
æµã
Cè¨èªã§GTK+ãç´æ¥ç¨ããå ´åã®æµãã®ä¾ã¨ãã¦ã¯
- ã¡ãã»ã¼ã¸ã®å½éåã«é¢ããå¦ç(ä»»æ/ã¡ãã»ã¼ã¸å½éåãè¡ãå ´åã®ã¿)
- gtk_init()ã«ããåæå
- GUIé¨åã®å¦ç(ä½æã表示,å種è¨å®ãªã©)
- GUIé¨åãã¨ã«ã¤ãã³ã(GObjectã·ã°ãã«)ã¨ãã³ãã©é¢æ°ãé¢é£ä»ã(æ¥ç¶)
- gtk_main()ã«ããã¡ã¤ã³ã«ã¼ãéå§
- ã¡ã¤ã³ã«ã¼ããæããå¾ã«è¡ãå¿ è¦ã®ããå¦çãããå ´åãå¿ è¦ã«å¿ãã¦è¨è¿°
ã®ããã«ãªãã
#include <gtk/gtk.h> #include <stdlib.h> int main (int argc, char **argv) { /* ã¡ãã»ã¼ã¸ã®å½éåãè¡ãå ´åã«ã¯bindtextdomain()ãªã©ã®é¢æ°ãããã§å¼ã¶ */ gtk_init (&argc, &argv); /* ããã«GUIé¨åã®å¦çã¨ã·ã°ãã«æ¥ç¶ãªã©ãè¨è¿°... */ gtk_main (); /* gtk_main_quit()ã«ããã¡ã¤ã³ã«ã¼ããæããã¨ãã«è¡ãããå¦çãããå ´åã¯ããã«è¨è¿° */ return EXIT_SUCCESS; }
ãã®ä»ãã³ãã³ãè¡å¼æ°ã®è§£æãªã©ã®å¥ã®å¦çãå¿ è¦ã§ããã°ãæåã®æ®µéã§è¡ãã
é常ã«ã·ã³ãã«ãªä¾
ä¸ã¯ãHelloãã¨æ¸ãããæ
å ±ãã¤ã¢ãã°ã表示ããéããã¨çµäºãããããã¯ãã¤ã¢ãã°ã®å®è¡ã®ã¿ã§ã¡ã¤ã³ã«ã¼ãã¯ç¨ãã¦ããªãã
[ä»»æ]ãã¡ã¤ã«å: infodialogtest.c
#include <gtk/gtk.h> #include <stdlib.h> /* * gcc -O2 -Wall -Wextra $(pkg-config --cflags --libs gtk+-2.0) infodialogtest.c -o infodialogtest */ int main (int argc, char **argv) { /* ãã¤ã¢ãã°ã®GUIé¨å */ GtkWidget *dialog; /* GTK+ã®åæå */ gtk_init (&argc, &argv); /* * ã¡ãã»ã¼ã¸ãã¤ã¢ãã°ãä½æ * http://library.gnome.org/devel/gtk/stable/GtkMessageDialog.html#gtk-message-dialog-new */ dialog = gtk_message_dialog_new (NULL, /* 親ã¦ã£ã³ã㦠or NULL */ 0, /* ãã¤ã¢ãã°ã®è¨å®ãã©ã° */ GTK_MESSAGE_INFO, /* ãã¤ã¢ãã°ã®ç¨®é¡ */ GTK_BUTTONS_CLOSE, /* ãã¿ã³ã®ä¸¦ã³ã®ç¨®é¡ */ "Hello"); /* ã¡ãã»ã¼ã¸å 容 */ /* ãã¤ã¢ãã°ãå®è¡ */ gtk_dialog_run (GTK_DIALOG (dialog)); /* ãGtkDialog *ãåãè¦æ± ãã¯ãã§åå¤æãã */ /* GUIé¨åãç ´æ£,ä¸ã«é¨åãå«ãå ´åã¯ãããå«ãã¦ç ´æ£ãã */ gtk_widget_destroy (dialog); /* ãã¤ã¢ãã°ãåºãã ãã®ããã°ã©ã ãªã®ã§ã¡ã¤ã³ã«ã¼ãã¯åããªãã§çµäºãã */ return EXIT_SUCCESS; }
ãã¼ã¿ã®åã¨gtk_dialog_run()ã®è¡ã®ãããªåå¤æ,gtk_widget_destroy()ã®å¦çãªã©ã«ã¤ãã¦ã¯別記事ã§æ±ãã
(ãC言語でGTK+ 2を扱う上での幾つかのメモ(第3回)ãã«ç¶ã)
é¢é£è¨äº: