如何通过检查gtk_dialog_run()
这就是我所拥有的
/*toolbar test thingy*/
#include <gtk/gtk.h>
#define MESSAGE_OK 1001
void mymessage (void){
GtkWidget *message = gtk_dialog_new_with_buttons("My dialog",
NULL,
GTK_DIALOG_MODAL,GTK_STOCK_OK,1001,NULL);
gtk_window_set_default_size(GTK_WINDOW(message),200,200);
gint result = gtk_dialog_run(GTK_DIALOG(message));
switch(result){
case MESSAGE_OK:
gtk_widget_destroy(message);
printf("you clicked message_ok");
break;
}
gtk_widget_destroy(message);
}
int main(int argc,char *argv[]){
GtkWidget *window;
GtkWidget *vertical_box;
GtkWidget *toolbar;
//GtkWidget *message;
GtkToolItem *tool_new;
gtk_init(&argc,&argv);
//setting up the main window.
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"rs-toolbar test");
gtk_window_set_default_size(GTK_WINDOW(window),300,350);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);
//setting up the layout using vbox.
vertical_box = gtk_vbox_new(FALSE,0);
//adding the vbox layout to the Container window, window
gtk_container_add(GTK_CONTAINER(window),vertical_box);
toolbar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),GTK_TOOLBAR_ICONS);
gtk_container_set_border_width(GTK_CONTAINER(toolbar),2);
tool_new = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar),tool_new,-1);
//************************************************************************
//************************************************************************
gtk_box_pack_start(GTK_BOX(vertical_box),toolbar,FALSE,FALSE,0);
gtk_widget_show_all(window);
g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
g_signal_connect(tool_new,"clicked",G_CALLBACK(mymessage),NULL);
gtk_main();
return 0;
}
使用gtk_dialog_new_with_buttons()
功能是否正确?我不完全确定如何为控件提供特定的ID。我试图做的是使1001成为GTK_STOCK_OK
的ID。