我使用Win7-64bit,gtk2.24.10,MSV C ++ 2012 当我编译这段代码时,我断言失败了。我想在窗口中添加菜单栏和表格,但不知道如何将它们链接到窗口以进行核心编译。
示例代码:
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *fileMenu;
GtkWidget *fileMi;
GtkWidget *newMi;
GtkWidget *openMi;
GtkWidget *cropMi;
GtkWidget *rotateMi;
GtkWidget *rotateMi1;
GtkWidget *rotateMi2;
GtkWidget *rotateMi3;
GtkWidget *rotateMi4;
GtkWidget *rotateMi5;
GtkWidget *rotateMi6;
GtkWidget *rotateMi7;
GtkWidget *rotateMi8;
GtkWidget *resizeMi,*imprMenu;
GtkWidget *runMi;
GtkWidget *quitMi;
GtkWidget *frame1;
GtkWidget *frame2;
GtkWidget *table;
GtkWidget *sep;
GtkAccelGroup *accel_group = NULL;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
gtk_window_set_title(GTK_WINDOW(window), "Images");
table = gtk_table_new(18,18,FALSE);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), table);
gtk_container_add(GTK_CONTAINER(table), vbox);
menubar = gtk_menu_bar_new();
fileMenu = gtk_menu_new();
accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
fileMi = gtk_menu_item_new_with_mnemonic("_File");
newMi = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL);
resizeMi = gtk_menu_item_new_with_label("Resize");
cropMi = gtk_menu_item_new_with_label("Crop");
rotateMi = gtk_menu_item_new_with_label("Rotate");
runMi = gtk_menu_item_new_with_label("Run");
rotateMi1 = gtk_menu_item_new_with_label("0 ");
rotateMi2 = gtk_menu_item_new_with_label("30");
rotateMi3 = gtk_menu_item_new_with_label("45");
rotateMi4 = gtk_menu_item_new_with_label("60");
rotateMi5 = gtk_menu_item_new_with_label("75");
rotateMi6 = gtk_menu_item_new_with_label("90");
rotateMi7 = gtk_menu_item_new_with_label("135");
rotateMi8 = gtk_menu_item_new_with_label("180");
openMi = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, NULL);
sep = gtk_separator_menu_item_new();
quitMi = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);
gtk_widget_add_accelerator(quitMi, "activate", accel_group,
GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
imprMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMi), fileMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), newMi);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), openMi);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), sep);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), cropMi);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), rotateMi);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), resizeMi);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), runMi);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(rotateMi), imprMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu), rotateMi1);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu), rotateMi2);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu), rotateMi3);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu), rotateMi4);
gtk_menu_shell_append(GTK_MENU_SHELL(imprMenu), rotateMi5);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), quitMi);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMi);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
//gtk_table_attach_defaults(GTK_TABLE(table),vbox,0,1,0,2);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(quitMi), "activate",
G_CALLBACK(gtk_main_quit), NULL);
table = gtk_table_new(18,18,FALSE);
frame1 = gtk_frame_new("Input X-ray Image");
frame2 = gtk_frame_new("Input Image");
gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_IN);
gtk_box_pack_start(GTK_BOX(vbox), frame1, FALSE, FALSE, 0);
gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_IN);
gtk_box_pack_start(GTK_BOX(vbox), frame2, FALSE, FALSE, 0);
gtk_table_attach_defaults(GTK_TABLE(table),frame1,0,1,0,2);
gtk_table_attach_defaults(GTK_TABLE(table),vbox,3,4,3,4);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
感谢您的关注..