用函数gtk_menu_item_set_use_underline设置快捷键时,使用Alt+下划线之后的字母实现。
当我在Visual Studio 2005中将代码写好,拷贝到Linux下,进行make时,出现了:
undefined reference to `gtk_menu_item_set_use_underline'错误,
前提:源程序在VS2005下编译成功,而且运行良好。
刚才在http://developer.gnome.org/gtk/2.24/GtkMenuItem.html上看到了这样一段话:
gtk_menu_item_get_use_underline ()
gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item);
Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.
原来是版本的问题 http://developer.gnome.org/gtk/2.24/GtkMenuItem.html上面显示的是这样的:
gtk_menu_item_set_use_underline ()
void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item,
gboolean setting);If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
menu_item :
a GtkMenuItem
setting :
TRUE if underlines in the text indicate mnemonics
今天在看gtk+API手册的时候发现了一个函数:gtk_menu_item_new_with_mnemonic ()
GtkWidget* gtk_menu_item_new_with_mnemonic (const gchar *label);
Creates a new GtkMenuItem containing a label. The label will be created using gtk_label_new_with_mnemonic(), so underscores in label indicate the mnemonic for the menu item.
label : The text of the button, with an underscore in front of the mnemonic character
Returns : a new GtkMenuItem
这个函数解决了那个问题。