ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxϵÄGTKͼÐνçÃæ±à³Ì

·¢²¼Ê±¼ä:2006-02-23 00:22:58À´Ô´:ºìÁª×÷Õß:root
¡¾ÕªÒª¡¿ ±¾ÎĽéÉÜÁËLinuxƽ̨ϵÄXwindowͼÐδ°¿Ú±à³Ì¹¤¾ßGTK£¬²¢¸ø³öÁËÓÃGTK±à³ÌµÄ»ù±¾ÒªËغͲ½Öè¡£

¡¾¹Ø¼ü´Ê¡¿GTK£¬»Øµ÷º¯Êý£¬ÏûÏ¢´¦ÀíÆ÷£¬µ÷½ÚÆ÷

GTK(GIMP Toolkit)ÊÇÒ»¸öͼÐÎÓû§±à³ÌµÄ½Ó¿Ú¹¤¾ß¡£Ëü×¢²áÍêÈ«Ãâ·Ñ£¬ËùÒÔÓÃÀ´¿ª·¢×ÔÓÉÈí¼þ»òÉÌÒµÈí¼þ¶¼²»ÐèÒª»¨·Ñʲô¡£ÏÖÔںܶàLinux¼¯³Éϵͳ¶¼ÒѾ­½«GTK1.2°æ±¾´ò°ü½øÈ¥ÁË¡£°üÀ¨RedHat Linux 6.0ÒÔÉÏ°æ±¾£¬»¹ÓÐÖÐÎÄ»¯µÄTurbo LinuxµÈµÈ¡£ËüÒ²Ô½À´Ô½±»ÆÕ±éµÄÓ¦ÓÃÓÚUNIXϵͳ±à³Ì¡£

»¹ÓÐÒ»¸ö×é¼þ½ÐGlib£¬Ëü°üº¬ÁËһЩ±ê×¼Ó¦ÓõÄÐÂÀ©Õ¹ÓÃÀ´Ìá¸ßGTKµÄ¼æÈÝÐÔ¡£ÓÃÓÚLinuxϵͳµÄijЩº¯Êý¿ÉÄܲ»Êʺϱê×¼µÄUNIXϵͳ£¬ÀýÈçg_strerror()º¯ÊýµÈµÈ¡£Ä³Ð©º¯ÊýÒ²À©Õ¹ÁËGNUCµÄÒ»°ã¹¦ÄÜ£¬ÀýÈçg_mallocº¯Êý¾ÍÓÐ×Ô¼º¼ÓÇ¿µÄµ÷ÊÔ¹¦ÄÜ¡£

GTK¿ÉÒÔÓë¶àÖÖÓïÑ԰󶨣¬°üÀ¨C++, Guile, Perl, Python, Ton, Ada95, Objective C, Free Pascal, Eiffel¡£Óñê×¼C¿ª·¢µÄ³ÌÐò£¬±àÒëÈí¼þ¿ÉÓÃGNU²¢¸½´øÉÏGTKÑ¡Ïî¼´¿É¡£ÏëÓóýÁ˱ê×¼CÒÔÍâµÄÆäËüÓïÑÔÀ´¿ª·¢XwindowͼÐÎÓû§³ÌÐò£¬ÔòÐèÒªÏȲο¼Ò»ÏÂÓйذó¶¨Èí¼þµÄÄÚÈÝ£¨HTTP:// www.gtk.org£©¡£ Èç¹ûÓÃC++ÓïÑÔÀ´µ÷ÓÃGTK½øÐпª·¢£¬¿ÉÒÔÓÃÒѾ­ºÍC++°ó¶¨µÄÈí¼þ½ÐGTK--Èí¼þ,À´Ìṩһ¸ö±ÈGTK¸üºÃµÄC++±àÒë»·¾³¡£

Ä¿Ç°ÒѾ­¿ª·¢³öÀ´GTKµÄÔöÇ¿°æGTK+¡£GTK+Êǽ«GTK£¬GDK£¬GLIB¼¯³ÉÔÚÒ»ÆðµÄ¿ª·¢°ü£¬¿ÉÒÔ¹¤×÷ÔÚÐí¶àÀàËÆÓÚUNIXµÄϵͳÉÏ£¬Ã»ÓÐGTKµÄƽ̨ÏÞÖÆ¡£

1£®GTKµÄÏûÏ¢´¦Àí»úÖÆ

ÏÂÃæÎÒÃÇÏÈ¿´Ò»¸ö»ù±¾µÄÀý×Ó£¬¸ÃÀý×Ó²úÉúÒ»¸ö200¡Á200ÏñËصĴ°¿Ú¡£Ëü²»ÄÜ×Ô¼ºÍ˳ö£¬Ö»ÄÜͨ¹ýshellÀ´É±ËÀ½ø³Ì£¨µ÷ÓÃkillÃüÁ¡£

ÒýÓÃ:
/*Àý×Ó base.c */

#include

int main( int argc,char *argv[ ] ){

GtkWidget *window;

gtk_init (&argc, &argv); /* ³õʼ»¯ÏÔʾ»·¾³ */

window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* ´´½¨Ò»¸öеĴ°¿Ú*/

gtk_widget_show (window); /*ÏÔʾ´°¿Ú*/

gtk_main (); /*½øÈë˯Ãß״̬£¬µÈ´ýʼþ¼¤»î*/

return(0);

}


´ÓÉÏÃæµÄ³ÌÐò¿ÉÒÔ¿´³ö£¬GTKÊÇÒ»¸öʼþÇý¶¯¹¤¾ß°ü£¬µ±ËüÔËÐе½gtk_main()º¯Êýʱ»á×Ô¶¯Ë¯Ãߣ¬Ö±µ½ÓÐʼþ·¢Éú£¬¿ØÖÆȨתÈøøÏàÓ¦µÄº¯Êýµ÷Óã¬Ôڸú¯ÊýÖпÉÒÔÓñê×¼Cд³öÏàÓ¦µÄÊÂÎïÂß¼­¡£ÕâÓëwindows ÉϵijÌÐò´¦ÀíÊÇÒ»ÑùµÄ¡£

¶Ô´°¿Ú¶ÔÏóÉÏ·¢ÉúµÄʼþ£¨Èç°´ÏÂÊó±ê£¬¼¤»î¼üÅ̵ȣ©£¬GTKÒ²ÓÐÏàÓ¦µÄÏûÏ¢ÐźŲúÉú¡£Õâʱ¾ÍÐèÒª³ÌÐòÔ±´´½¨Ò»¸öÐźŴ¦ÀíÆ÷À´²¶»ñ¸ÃÐźţ¬²¢¸æËßGTK³ÌÐòʼþ·¢Éúºóµ÷ÓÃÄĸö»Øµ÷º¯Êý¡£ÐźŴ¦ÀíÆ÷µÄ´´½¨º¯Êý¶¨ÒåÈçÏ£º

gint gtk_signal_connect( GtkObject *object, gchar *name,

GtkSignalFunc callback_func, gpointer func_data );

·µ»ØÖµÊÇÒ»¸öÇø·Öͬһ¶ÔÏóÖеÄʼþÓ벻ͬ»Øµ÷º¯ÊýµÄ¹ØÁª±êÇ©¡£ÕâÑù¿ÉÒÔ×öµ½Ò»¸ö¶ÔÏóµÄÒ»¸öÐźžÍÓÐÈÎÒâ¶à¸ö»Øµ÷º¯Êý£¬²¢ÇÒÿһ¸ö¶¼»á°´ÕÕÉùÃ÷µÄ˳ÐòÖ´ÐС£º¯Êýµ÷ÓõĵÚÒ»¸ö²ÎÊýÊDzúÉúÐźŵÄwidget×é¼þ£¨¼´°´Å¥µÈ´°¿Ú¹¹¼þ£©£¬¶ønameÔòÊÇÏ£Íû²¶»ñµÄÐźŻòʼþµÄÃû³Æ£¬callback_funcÔòÊÇʼþ·¢ÉúºóËùµ÷ÓõĻص÷º¯ÊýÃû³Æ£¬¶øµÚËĸö²ÎÊýfunc_dataÔòÊÇ´«µÝ¸ø»Øµ÷º¯ÊýµÄ²ÎÊý¡£

»Øµ÷º¯ÊýÒª¶¨ÒåÔÚÖ÷³ÌÐòµÄÇ°Ã棬ËüÃǵÄÒ»°ã¸ñʽ¶¼ÈçÏÂËùʾ£º

void callback_func( GtkWidget *widget, gpointer func_data );

µ÷ÓÃÏÂÃæÕâ¸ö·½·¨½«ÔÊÐíÄ㽫»Øµ÷º¯ÊýÓëʼþµÄ¹ØÁª¶Ï¿ª£º

void gtk_signal_disconnect( GtkObject *object, gint id );

¸Ãº¯ÊýµÄµÚ¶þ¸ö²ÎÊý¾ÍÊÇÉÏÊögtk_signal_connect£¨£©º¯ÊýµÄ·µ»ØÖµ£¬¼´¹ØÁª±êÇ©¡£µÚÒ»¸ö²ÎÊýÖ¸ÏòÁËÈ¥³ý¹ØÁªµÄ¶ÔÏóÃû³Æ¡£ÕâÑù¿ÉÒÔ×öµ½¶Ï¿ªÊ¼þÓë»Øµ÷º¯ÊýµÄ¹ØÁª£¬Ê¹µÃʼþ·¢Éúºó£¬²»»áµ÷ÓÃÏà¹ØµÄ»Øµ÷º¯Êý¡£

²¼¾Ö¸ñʽ


2.1´ò°üºÐ×Ó

¶ÔGTKÏÔʾ¸ñʽµÄ¿ØÖÆÊÇͨ³£Í¨¹ý´ò°üºÐ×ÓÀ´Íê³ÉµÄ¡£widget×é¼þ´ò°ü¿ÉÒÔ²ÉÓÃÁ½ÖÖ·½Ê½£¬Ë®Æ½ºÐ×Ӻʹ¹Ö±ºÐ×Ó¡£Èô½«widget×é¼þ´ò°ü½øƽÐкÐ×Ó£¬×é¼þ¾Í±»ÒÀ´ÎˮƽµÄ²åÈë´°¿Ú£»ÈôÊÇ´¹Ö±ºÐ×Ó£¬Ôò×é¼þÅÅÁÐÊÇ´¹Ö±µÄ¡£²úÉúеÄˮƽºÐ×ӵĺ¯ÊýΪ

GtkWidget *gtk_hbox_new (gint homogeneous, gint spacing);

²ÎÊýhomogeneousÊÇÓÃÀ´¿ØÖÆÊÇ·ñºÐ×ÓÖеÄÿ¸ö×é¼þ¶¼ÓÐͬÑùµÄ´óС£¨ÀýÈçˮƽºÐ×ÓÖеĿؼþÓÐͬÑùµÄ¿í¶È£¬´¹Ö±ºÐ×ÓÖеĿؼþÓÐͬÑùµÄ¸ß¶È£©¡£Spacing²ÎÊýÊÇ×é¼þÖ®¼äµÄ¼ä¸ô¡£

´¹Ö±ºÐ×ӵĴ´½¨º¯ÊýÊÇgtk_vbox_new£¨£©£¬¶¨ÒåÓëˮƽºÐ×ÓÒ»Ö¡£

gtk_box_pack_start()ºÍgtk_box_pack_end()º¯ÊýÊÇÓÃÀ´½«´ò°ü¶ÔÏó·ÅÈëÕâЩºÐ×ÓÖеġ£

void gtk_box_pack_start( GtkBox *box, GtkWidget *child,

gint expand, gint fill, gint padding );

µÚÒ»¸ö²ÎÊýÊÇÄ㽫×é¼þ´ò½øÈ¥µÄºÐ×ÓÖ¸Õ룬µÚ¶þ¸ö²ÎÊýÊÇÄ㽫Ҫ´ò½øÈ¥µÄ×é¼þÖ¸Õë¡£Expand²ÎÊýÊÇÓÃÀ´¿ØÖÆÊÇ·ñÔÊÐí×é¼þÀ©Õ¹ÖÁ·ÖÅä¸øºÐ×Ó¿Õ¼äµÄ´óС£¨Ñ¡TRUE£©£¬»¹ÊǺÐ×ӵĴóСÊÕËõµ½×é¼þÄÇô´ó£¨Ñ¡FALSE£©¡£º¯ÊýÖеÄfill²ÎÊýÊÇÓÃÀ´¿ØÖÆÊÇ·ñ½«¶àÓàµÄ¿Õ¼ä·ÖÅä¸ø×é¼þ£¬¼´½«×é¼þÀ©Õ¹µ½ºÐ×ӵĴóС£¨Ñ¡TRUE£©£¬»òÕ߶àÓàµÄ¿Õ¼ä²»±ä£¬±£Áô×÷ΪºÐ×Ӻʹò°ü×é¼þ¼äµÄ¼ä¸ô¡£¸Ã²ÎÊýÖ»ÓÐÔÚexpand²ÎÊýÈ¡TRUEʱ²ÅÓÐЧ¡£Padding²ÎÊýÊÇÖ¸×é¼þËÄÖÜÓëºÐ×ӵļä¸ô´óС¡£

×¢ÒâfillÈ¡FALSEÖµ£¬expandÈ¡TRUEֵʱÓëexpandÈ¡FALSEÖµ£¬fillÖµÎÞЧµÄÇø±ð¡£Ç°ÕߵĺÐ×ÓÈÔÊÇÔ­À´´´½¨ºÐ×Óʱָ¶¨µÄ´óС£¬¶øºóÕߵĺÐ×ÓÒѾ­ËõСµ½´ò°ü×é¼þµÄ´óСÁË¡£

gtk_box_pack_end()º¯ÊýµÄ²ÎÊýÓëÉÏÃæÃèÊöµÄÒ»Ö¡£Ö»ÊÇÅÅÁÐ˳Ðò·Ö±ðÊÇ´Óϵ½ÉÏ£¬´ÓÓÒµ½×ó¡£

×îºó½«ËùÓеĺÐ×Ó»ò×é¼þ´ò°üµ½Ò»¸ö´óºÐ×ÓÖУ¬ÓÃgtk_container_add()º¯Êý½«ºÐ×Ó¼ÓÈë´°¿Ú¼´¿É¡£

2.2±í¸ñ´ò°ü

ÎÒÃÇ¿ÉÒÔ²úÉúÒ»¸ö±í¸ñ£¬½«widget×é¼þÒ»Ò»·ÅÈë¡£Widget×é¼þ½«Õ¼¾ÝËùÓзÖÅä¸øËüµÄ¿Õ¼ä¡£´´½¨±í¸ñÊÇÓÃÏÂÃæµÄº¯Êý£º

GtkWidget *gtk_table_new( gint rows, gint columns,

gint homogeneous );

µÚÒ»¸ö²ÎÊý£¬ÏÔ¶øÒ×¼û£¬ÊDZí¸ñµÄÐÐÊý¡£ºóÃæµÄ²ÎÊýÔòÊDZí¸ñµÄÁÐÊý¡£homogeneous²ÎÊýÔòÊÇÓÃÀ´°²Åűí¸ñ¼ä¸ô´óС¡£Èç¹ûËüÈ¡TRUE£¬Ôò±í¸ñÖÐÿ¸öС¸ñµÄ´óСÓñí¸ñÖÐ×î´ó×é¼þµÄ´óСÀ´ÉèÖõģ¬ËùÓеÄС¸ñ´óС¶¼ÊÇÒ»ÑùµÄ¡£Èç¹ûhomogeneous²ÎÊýÈ¡FALSEµÄ£¬Ã¿¸öС¸ñµÄ´óС¶¼ÓÃͬÐÐÖÐ×î¸ß×é¼þµÄ¸ß¶È£¬Í¬ÁÐÖÐ×î¿í×é¼þµÄ¿í¶È¡£

½«Ò»¸öwidget×é¼þ·ÅÈëÒ»¸ö±í¸ñ£¬ÓÃÏÂÃæµÄº¯Êý£º

void gtk_table_attach( GtkTable *table, GtkWidget *child, gint left_attach,

gint right_attach, gint top_attach, gint bottom_attach,

gint xoptions, gint yoptions, gint xpadding, gint ypadding );

left_attach²ÎÊýºÍright_attach²ÎÊý½«Ö¸³öÔÚÄĶù·ÅÖÃ×é¼þ£¬ÒÔ¼°ÓÃÁ˶àÉÙºÐ×Ó¡£Èç¹ûÄãÏëÔÚÁ½ÐÐÁ½Áеıí¸ñÖеÄÓÒÏÂС¸ñÖмÓÈëÒ»¸ö°´Å¥£¬²¢ÇÒÏëÈð´Å¥³äÂúÄǸöС¸ñ£¬Ôò²ÎÊý¿ÉÒÔÑ¡Ôñleft_attach = 1, right_attach = 2, top_attach = 1, bottom_attach = 2¡£Æäʵleft_attachÒ²¾ÍÊÇ×é¼þËùÔÚС¸ñµÄ×ó±ß¿òÊDZí¸ñµÄµÚ¼¸Ìõ±ßÊý£¬ÆäËüÒÀ´ËÀàÍÆ¡£

²ÎÊýxoptionsºÍyoptionsÊÇÓÃÀ´È·¶¨´ò°üÑ¡ÏîµÄ£¬¿ÉÒÔÓÃORÀ´Ñ¡Ôñ¶à¸öÑ¡Ïî¡£

µ÷½ÚÆ÷

GTKÓкܶà×é¼þ¿ÉÒÔÓÃÊó±ê»ò¼üÅÌÀ´µ÷Õû£¬ÀýÈ緶Χ×é¼þ£¨Range Widget£©¡£»¹ÓÐһЩ×é¼þÔÚÕû¸öÊý¾ÝÇøÓòµÄÒ»²¿·ÖÊǿɵ÷ÕûµÄ£¬ÀýÈçÎı¾×é¼þ£¨Text Widget£©ºÍÊÓ¿Ú×é¼þ£¨Viewport Widget£©¡£

ºÜÃ÷ÏÔ£¬³ÌÐòÊÇÒªÄܹ»¶Ô¿Éµ÷Õû×é¼þËù²úÉúµÄ±ä»¯½øÐд¦Àí¡£Ò»ÖÖ½â¾ö°ì·¨ÊÇÈÿɵ÷Õû×é¼þÔÚÊÍ·Å×Ô¼ºµÄÐźÅʱ£¬½«µ÷ÕûÊý¾ÝÖµ´«µÝÐźŴ¦ÀíÆ÷¡£»òÕßÓÃÁíÍâÒ»ÖÖ½â¾ö·½·¨½«µ÷ÕûÊý¾ÝÖµ·ÅÈëÒ»¸öÊý¾Ý½á¹¹£¬ÓɳÌÐò·ÃÎʸýṹÀ´»ñµÃ¸Ä±äµÄ²ÎÊýÖµ¡£ÓÐʱºòÄã¿ÉÄÜÐèÒª½«¼¸¸ö¿Éµ÷Õû×é¼þµÄµ÷½ÚÏà¹ØÁª£¬µ÷ÕûÒ»¸öÒ²»áµ¼ÖÂÁíÒ»¸öµÄ±ä»¯¡£×îÃ÷ÏÔµÄÀý×Ó¾ÍÊǹö¶¯ÌõÓëÎı¾±à¼­¿ò×é¼þµÄ´¦Àí¡£Èç¹ûÕâЩÏà¹ØÁªµÄ×é¼þ·Ö±ðÓÐ×Ô¼º´¦Àíµ÷ÕûÊý¾ÝµÄ·½·¨£¬Ôò³ÌÐòÔ±±ØÐë×Ô¼ºÐ´Ò»¸öÐźŴ¦ÀíÆ÷£¬½«Ò»¸ö×é¼þµÄµ÷ÕûÊý¾Ýת»»³ÉÁíÒ»¸ö×é¼þµÄµ÷ÕûÊý¾Ý£¬²¢µ÷Óõ÷ÕûÉèÖú¯Êý½«¸ÃÖµÉèÖýøÈ¥¡£

GTKµ÷ÓÃÁ˵÷½ÚÆ÷³É¹¦µÄ½â¾öÁËÕâ¸öÎÊÌâ¡£µ÷½ÚÆ÷²»ÊÇ×é¼þ£¬¶øÊÇ´æ´¢ºÍ´«µÝµ÷ÕûÊý¾ÝµÄ½á¹¹¡£×îµäÐ͵ĵ÷ÕûÆ÷Ó¦ÓÃÊÇ´æ´¢ÅäÖòÎÊýºÍ·¶Î§×é¼þµÄÖµ¡£²»Í¬µÄÊǵ÷ÕûÆ÷Ò²ÊÇ´Ó¶ÔÏó£¨Object£©¼Ì³Ð¶øÀ´µÄ£¬ËüÓÐÐí¶à²»Í¬ÓÚÊý¾Ý½á¹¹µÄÌØÐÔ¡£×îÖØÒªµÄÊÇ£¬ËüÒ²»áÊÍ·ÅÐźţ¬²¢ÇÒÕâЩÐźŲ»½ö¿ÉÒÔ±»³ÌÐò²¶»ñÀ´ÏìÓ¦Óû§µÄµ÷ÕûºÍ±à¼­£¬»¹¿ÉÒÔÔڿɵ÷Õû×é¼þÖÐ͸Ã÷µÄ´«²¥µ÷ÕûÊý¾Ý¡£

Ò»°ãµ÷½ÚÆ÷»á´´½¨×é¼þʱ×Ô¶¯´´½¨¡£ÀýÈçÈÃÎı¾×é¼þºÍ¹ö¶¯Ìõ×é¼þÓÃͬһ¸öµ÷½ÚÆ÷ÈçÏÂËùʾ£º

text = gtk_text_new (NULL, NULL);

/* ½«¸Õ´´½¨µÄµ÷½ÚÆ÷ÓÃÓÚ´¹Ö±¹ö¶¯Ìõ */

vscrollbar = gtk_vscrollbar_new (GTK_TEXT(text)->vadj);

µ÷½ÚÆ÷ÊÇ´Ó¶ÔÏóObject¼Ì³ÐÏÂÀ´µÄ¡£ËùÒÔËüÓëÆäËüµÄ×é¼þ¶ÔÏóÒ»Ñù£¬Äܹ»²úÉúÐźš£µ±ºÃ¼¸¸ö×é¼þ¹²ÏíÒ»¸öµ÷½ÚÆ÷ʱ£¬ËüÃǶ¼»áºÍÒ»¸öÐźŴ¦ÀíÆ÷Ïà¹ØÁª¡£Õâ¸öÐźŴ¦ÀíÆ÷ÊÇÓÃÀ´´¦Àí¡°value_changed¡±Ðźŵģ¬¸ú³ÌÐòÖд¦ÀíÐźÅÊÇÒ»Ñù¡£ÏÂÃæÊÇÔÚGtkAdjustmentClass½á¹¹ÖиÃÐźŵĶ¨Ò壺

void (* value_changed) (GtkAdjustment *adjustment);

²»Í¬µÄ¿Éµ÷Õû×é¼þ¶¼ÓÃÒ»¸öµ÷½ÚÆ÷ʱ£¬ÈκÎÒ»¸ö×é¼þ·¢Éúµ÷Õû±ä»¯¶¼»á²úÉú¸ÃÐźš£ÓÐÁ½ÖÖÇé¿ö»áµ¼ÖÂÕâ¸öÏÖÏóµÄ·¢Éú¡£µÚÒ»ÖÖÇé¿öÊÇÓû§ÔÚÓÃÊó±ê»ò¼üÅ̵÷Õû¸Ã×é¼þ£¨ÀýÈçÀ­¹ö¶¯Ìõ£©£¬»òÕßÖ±½ÓÔÚ³ÌÐòÖÐÓÃgtk_adjustment_set_value()º¯ÊýÀ´¸Ä±äµ÷½ÚÆ÷ÖеÄvalueÖµ¡£

µ±µ÷½ÚÆ÷µÄupper²ÎÊýºÍlower²ÎÊý±»ÖØÐÂÅäÖÃʱ£¬¾ÍÏóÓû§ÐèÒª¸øÒ»¸öÎı¾±à¼­¿ò¼ÓÈëÁ˸ü¶àµÄÎı¾ºó£¬µ÷½ÚÆ÷¾Í»áÊͷųö¡°changed¡±Ðźš£ËüµÄ¶¨ÒåÈçÏ£º

void (* changed) (GtkAdjustment *adjustment);

·¶Î§×é¼þ½«¸ÃÐźÅÓëÒ»¸öÐźŴ¦ÀíÆ÷Ïà¹ØÁª£¬²¢ËæʱÔÚÃæ°åÉÏ·´Ó³²ÎÊýµÄ±ä»¯¡£¾Ù¸öÀý×Ó£¬¹ö¶¯ÌõÖ묶¯¼üµÄ´óСÓëµ÷½ÚÆ÷ÖÐupper£¬lowerÖµÖ®²îÕýºÃ³É·´±È¡£Ò»µ©Ç°ÕßÓÐÈκθı䣬Ãæ°åÉϵÄÏÔʾҲ»áÏàÓ¦²úÉú±ä»¯¡£

²»ÐèÒªÔÚ³ÌÐòÖн«Ò»¸öÐźŴ¦ÀíÆ÷Óë¸ÃÐźÅÏà¹ØÁª£¬Ò»Çж¼ÊÇGTKÍê³ÉµÄ¡£Èç¹ûÄãÖ±½ÓÉèÖÃÁ˵÷½ÚÆ÷µÄÕâЩ²ÎÊý£¬ÔòÐèÒªÔÚ³ÌÐòÖе÷ÓÃÏÂÃæµÄÓï¾äÀ´ÊÍ·ÅÐźţº

gtk_signal_emit_by_name (GTK_OBJECT (adjustment), "changed");

´´½¨×é¼þС½á
´ÓÉÏÃæ¿É¿´³ö£¬´´½¨Ò»¸öwidget×é¼þ¿ÉÒÔÓÃÒÔϼ¸¸ö²½ÖèÍê³É£º

gtk_*_new()--µ÷ÓÃÒ»¸ö·Ç³£ÓÐÓõĺ¯ÊýÀ´²úÉúÒ»¸öеÄwidget×é¼þ¡£


4.2ÓÃgtk_box_pack_start£¨£©º¯ÊýÁ¬½ÓËùÓеÄÐźźÍʼþ£¬²úÉúÏàÓ¦µÄʼþ´¦ÀíÆ÷À´µ÷Óûص÷º¯Êý¡£

4.3ÉèÖÃwidget×é¼þÒÔ¼°µ÷½ÚÆ÷µÄÌØÐÔ¡£

4.4ÓúÏÊʵĺ¯Êý½«widget×é¼þ´ò°üµ½Ò»¸öÈÝÆ÷£¨ºÐ×Ó»ò±í¸ñ£©ÖУ¬ÀýÈçgtk_box_container_start()º¯Êý»òÕßgtk_container_add()º¯ÊýµÈ¡£

4.5ÓÃgtk_widget_show()º¯ÊýÀ´ÏÔʾ×é¼þ¡£

ÓÃÉÏÊö·½·¨¿É´´½¨³ö³ÌÐòÔ±ËùÐèÒªµÄÈÎÒâ´°¿Ú¹¹¼þ£¬ÔÙ½«ÈÝÆ÷´òÈë´°¿Ú²¢ÏÔʾ´°¿ÚÖ®ºó£¬³ÌÐò±ã½øÈëÖ÷Ñ­»·Ë¯Ãß״̬£¬Ö÷³ÌÐò±àÖÆÒ²¾Í½áÊøÁË¡£Ê¼þµÄ´¦ÀíÂß¼­·Åµ½»Øµ÷º¯ÊýÖбàÖÆ¡£

±àÒë³ÌÐòÓÃÏÂÃæµÄÃüÁ

gcc my_prog.c -o my_prog.o -lgtk -lgdk ?

Íê³ÉºóÔÚXwindow»·¾³ÏÂÔËÐÐmy_prog.o³ÌÐò¼´¿É¡£



Ä¿Ç°X´°¿Ú£¨Xwindow£©ºÍGNU±àÒëϵͳÒѳÉΪӦÓÃlinux»òunix²Ù×÷ϵͳµÄ¼ÆËã»ú¹¤×÷Õ¾ºÍ´óÐͼÆËã»úÉÏ×îÖ÷ÒªµÄͼÐÎÓû§½çÃæϵͳ£¬ÔÚ΢»úÉÏÒ²Óй㷺ӦÓ᣶øGTKÕýÊÇÁ½Õß½áºÏµÄ±à³Ì¿ª·¢°ü¡£Ëü±ÈÒÔÍùÓõÄXwindow/Motif±à³Ì¸üΪ¼òµ¥·½±ã£¬¹¦ÄÜÒ²ºÜÇ¿´ó£¬ÓÐ׎ϺõÄÓ¦ÓÃÇ°¾°¡£Ä¿Ç°ÍøÉÏÒѾ­ÓкܶàÀûÓøÃÈí¼þ°ü¿ª·¢³öÀ´µÄ×ÔÓÉ·¢²¼Èí¼þ£¬¼«´óµÄ·á¸»ÁËLinuxƽ̨µÄÓ¦Óá£

[²Î¿¼ÎÄÏ×]

1.¡¶GTK Turtoil¡· Peter Mattis, Spencer Kimball, Josh MacDonaldÖø http://www.gtk.org



2.¡¶linuxϵͳ¹ÜÀíÖ¸ÄÏ¡· M.F.Komarinski£¬C.ColletÖø Ïþ¶¬ Âí¶¡Òë 1999£¬Ç廪´óѧ³ö°æÉç

3.¡¶UNIXÍøÂç±à³Ì¡· W.Richard StevensÖø 1998£¬Ç廪´óѧ³ö°æÉç
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 2 ÌõÆÀÂÛ

  1. tomorrow207 ÓÚ 2009-12-02 10:15:58·¢±í:

    ¶àл¥Ö÷¹²Ïí°¡£¬Â¥Ö÷ÐÁ¿àÁË

  2. yangar ÓÚ 2009-08-11 16:33:42·¢±í:

    ºÃ¶«¶«¡£¡£Ñ§Ï°ÖС£¡£Â¥Ö÷Ò²ÐÁ¿àÁË¡£