当前位置: 技术问答>linux和unix
在看GTK+2.0教程,在菜单构件那一节,我copy的示例程序为什么有个button构件显示不出来?
来源: 互联网 发布时间:2016-07-14
本文导语: #include #include static gint button_press(GtkWidget *, GdkEvent *); static void menuitem_response(gchar *); int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *menu; GtkWidget *menu_bar; GtkWidget *root_menu; GtkWidget *...
#include
#include
static gint button_press(GtkWidget *, GdkEvent *);
static void menuitem_response(gchar *);
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *menu;
GtkWidget *menu_bar;
GtkWidget *root_menu;
GtkWidget *menu_items;
GtkWidget *vbox;
GtkWidget *button;
char buf[128];
int i;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(GTK_WIDGET(window), 200, 100);
gtk_window_set_title(GTK_WINDOW(window), "GTK Menu Test");
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_main_quit), NULL);
/* 初始化菜单构件,不要用gtk_widget_show()来显示菜单构件。 */
menu = gtk_menu_new();
for (i = 0; i type == GDK_BUTTON_PRESS)
{
// printf("Press buttonn");
GdkEventButton *bevent = (GdkEventButton *)event;
gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
}
/* 告诉调用代码已经处理了这件事,事情传播(buck)在这里停止。 */
return TRUE;
}
static void menuitem_response(gchar *string)
{
printf("%sn", string);
}
|
button = gtk_button_new_with_label("press me");
/*g_signal_connect_swapped(G_OBJECT(button), "event",
G_CALLBACK(button_press), menu);*/
gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, TRUE, 2);
去掉信息就好,为什么你自己找吧
/*g_signal_connect_swapped(G_OBJECT(button), "event",
G_CALLBACK(button_press), menu);*/
gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, TRUE, 2);
去掉信息就好,为什么你自己找吧