Advertisement
palmerstone

Gtk

Nov 16th, 2011
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <gtk/gtk.h>
  4. #include <cairo.h>
  5.  
  6. GtkWidget *window;
  7. GtkWidget *box, *vbox;
  8. GtkWidget *menubar;
  9. GtkWidget *filemenu, *help, *helpmenu;
  10. GtkWidget *file, *quit, *open, *save, *properties, *about, *test;
  11. GtkWidget *img;
  12.  
  13. void CreateMenu()
  14. {
  15. vbox = gtk_vbox_new(FALSE, 0);
  16. box = gtk_vbox_new(FALSE, 0);
  17. gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, 0);
  18. menubar = gtk_menu_bar_new();
  19. filemenu = gtk_menu_new();
  20.  
  21. file = gtk_menu_item_new_with_label("File");
  22. quit = gtk_menu_item_new_with_label("Quit");
  23. open = gtk_menu_item_new_with_label("Open");
  24. save = gtk_menu_item_new_with_label("Save");
  25. properties = gtk_menu_item_new_with_label("Properties");
  26.  
  27. gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  28. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  29. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
  30. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), properties);
  31. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  32. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  33.  
  34. helpmenu = gtk_menu_new();
  35. about = gtk_menu_item_new_with_label("About");
  36. help = gtk_menu_item_new_with_label("Help");
  37. gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
  38. gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
  39. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
  40. gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);
  41. }
  42.  
  43. void show_about()
  44. {
  45. GtkWidget *dialog;
  46. const char *author[]={"None yet", "(However, Special thanks to Mehedi Hasan :-) )",NULL};
  47. dialog=gtk_about_dialog_new();
  48. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"You just clicked about!");
  49. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  50. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"Good job and go to hell");
  51. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
  52. gtk_dialog_run(GTK_DIALOG(dialog));
  53. }
  54.  
  55. int main(int argc, char*argv[])
  56. {
  57. gtk_init(&argc, &argv);
  58. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  59. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  60. gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
  61. gtk_window_set_title(GTK_WINDOW(window), "Aaarghhhh");
  62. CreateMenu();
  63. img = gtk_image_new_from_file("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg");
  64. gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  65. gtk_container_add(GTK_CONTAINER(window), box);
  66.  
  67. g_signal_connect_swapped(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
  68. g_signal_connect_swapped(G_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), NULL);
  69. g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
  70.  
  71. gtk_widget_show_all(window);
  72. gtk_main();
  73. return 0;
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement