Advertisement
thecplusplusguy

GTK+ tutorial 14

Jun 27th, 2012
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //Thanks for the typed in code to Tapit85
  3. #include <gtk/gtk.h>
  4. #include <string>
  5.  
  6. static void open_dialog(GtkWidget* button, gpointer window)
  7. {
  8.     GtkWidget *dialog, *label;
  9.     dialog = gtk_dialog_new_with_buttons("Dialog", GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
  10.     label = gtk_label_new("You clicked the button");
  11.     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog) -> vbox), label, 0,0,0);
  12.     gtk_widget_show_all(dialog);
  13.     gint response = gtk_dialog_run(GTK_DIALOG(dialog));
  14.     if(response == GTK_RESPONSE_OK)
  15.         g_print("You klicked OK\n");
  16.     else
  17.         g_print("You klicked Cancel\n");
  18.     gtk_widget_destroy(dialog);
  19. }
  20.  
  21. int main(int argc, char* argv[])
  22. {
  23.     gtk_init(&argc, &argv);
  24.     GtkWidget *window, *button;
  25.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  26.     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
  27.  
  28.     button = gtk_button_new_with_label("Click me");
  29.     g_signal_connect(button, "clicked", G_CALLBACK(open_dialog), window);
  30.     gtk_container_set_border_width(GTK_CONTAINER(window), 100);
  31.     gtk_container_add(GTK_CONTAINER(window), button);
  32.  
  33.  
  34.     gtk_widget_show_all(window);
  35.     gtk_main();
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement