源代码如下:
/*AUTOR:XIXI DATE:2020.4.1 23:37:16 */ #include<gtk/gtk.h> void delete_event(GtkWidget *widget,GdkEvent *event,gpointer data){ gtk_main_quit(); } int main(int argc,char* argv[]){ GtkWidget *window; GtkWidget *vbox; GtkWidget *rootmenu1; GtkWidget *rootmenu2; GtkWidget *rootmenu3; GtkWidget *rootmenu4; GtkWidget *menubar; GtkAccelGroup *accel_group; GtkWidget *arrivemenu; GtkWidget *leavemenu; GtkWidget *showmenu; GtkWidget *mapmenu; GtkWidget *menuitem; char* title="汽车站出租车拉客系统"; gtk_init(&argc,&argv); window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),title); gtk_widget_set_size_request(window,500,450); gtk_container_set_border_width(GTK_CONTAINER(window),10); g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL); arrivemenu=gtk_menu_new(); menuitem=gtk_menu_item_new_with_label("车牌号"); gtk_menu_shell_append(GTK_MENU_SHELL(arrivemenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("到达时间"); gtk_menu_shell_append(GTK_MENU_SHELL(arrivemenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("停放位置"); gtk_menu_shell_append(GTK_MENU_SHELL(arrivemenu),menuitem); gtk_widget_show(menuitem); rootmenu1=gtk_menu_item_new_with_label("车辆到达"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu1),arrivemenu); menubar=gtk_menu_bar_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu1); gtk_widget_show(rootmenu1); leavemenu=gtk_menu_new(); menuitem=gtk_menu_item_new_with_label("车牌号"); gtk_menu_shell_append(GTK_MENU_SHELL(leavemenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("离开时间"); gtk_menu_shell_append(GTK_MENU_SHELL(leavemenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("应付费用"); gtk_menu_shell_append(GTK_MENU_SHELL(leavemenu),menuitem); gtk_widget_show(menuitem); rootmenu2=gtk_menu_item_new_with_label("车辆离开"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu2),leavemenu); gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu2); gtk_widget_show(rootmenu2); showmenu=gtk_menu_new(); menuitem=gtk_menu_item_new_with_label("显示..."); gtk_menu_shell_append(GTK_MENU_SHELL(showmenu),menuitem); gtk_widget_show(menuitem); rootmenu3=gtk_menu_item_new_with_label("车场情况"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu3),showmenu); gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu3); gtk_widget_show(rootmenu3); mapmenu=gtk_menu_new(); menuitem=gtk_menu_item_new_with_label("九江地点查询"); gtk_menu_shell_append(GTK_MENU_SHELL(mapmenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("最短路径导航"); gtk_menu_shell_append(GTK_MENU_SHELL(mapmenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("查看地点信息"); gtk_menu_shell_append(GTK_MENU_SHELL(mapmenu),menuitem); gtk_widget_show(menuitem); menuitem=gtk_menu_item_new_with_label("查看推荐路径"); gtk_menu_shell_append(GTK_MENU_SHELL(mapmenu),menuitem); gtk_widget_show(menuitem); accel_group=gtk_accel_group_new();//组合器将子菜单优化 gtk_window_add_accel_group(GTK_WINDOW(window),accel_group); menuitem=gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW,accel_group); gtk_menu_shell_append(GTK_MENU_SHELL(mapmenu),menuitem); gtk_widget_show(menuitem); rootmenu4=gtk_menu_item_new_with_label("导航功能"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(rootmenu4),mapmenu); gtk_menu_shell_append(GTK_MENU_SHELL(menubar),rootmenu4); gtk_widget_show(rootmenu4); gtk_widget_show(menubar); vbox=gtk_vbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),menubar,FALSE,FALSE,0); gtk_widget_show(vbox); gtk_container_add(GTK_CONTAINER(window),vbox); gtk_widget_show_all(window); gtk_main(); return 0; }
这个代码逻辑比较简单!
正是步行者,一步步登峰!
原文:https://www.cnblogs.com/ouyangmail/p/12616876.html