GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 9:42 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GTK 3 Problems
PostPosted: Sat May 05, 2012 3:31 pm 
Offline

Joined: Sat May 05, 2012 3:06 pm
Posts: 2
Hello, I have a problem with gtk + 3 creates a menu for my application, I find no solution here and the source code of the application, thank you for helping me to realize the application menu.


Code:
#include<gtk/gtk.h>
#include<stdlib.h>
#include<stdio.h>

void destroy(GtkWidget *p_window, gpointer data)
{
    gtk_main_quit();
}

void OnQuitter(GtkWidget* widget, gpointer data)
{
GtkWidget *pQuestion;
pQuestion = gtk_message_dialog_new(GTK_WINDOW(data),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"Voulez vous vraiment\n"
"quitter le programme?");
switch(gtk_dialog_run(GTK_DIALOG(pQuestion)))
{
case GTK_RESPONSE_YES:
gtk_main_quit();
break;
case GTK_RESPONSE_NONE:
case GTK_RESPONSE_NO:
gtk_widget_destroy(pQuestion);
break;
}
}

void OnAbout(GtkWidget* widget, gpointer data)
{
GtkWidget *pAbout;
pAbout = gtk_message_dialog_new (GTK_WINDOW(data),
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Cours GTK+ 2.0\n"
"http://www.gtk-fr.org");
gtk_dialog_run(GTK_DIALOG(pAbout));
gtk_widget_destroy(pAbout);
}

static const char *tableau[]={"Profil","Enregistrer","Enregistrer sous...","Quitter"};

static void menu_cb(GtkMenuItem *item,gpointer data)
{
    printf("%s\n",gtk_menu_item_get_label(item));
}

int main(int argc, char *argv[])
{

GtkWidget *p_window/*,*bouton[4]*/,*grid,*barre_menu,*menu,*sous_menu_fichier,*vbox;
gtk_init(&argc, &argv);
int i;
p_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(p_window),"Tour de Hanoi");
gtk_container_set_border_width(GTK_CONTAINER(p_window),10);
gtk_widget_set_size_request(p_window,700,350);
g_signal_connect (G_OBJECT (p_window), "destroy", G_CALLBACK (destroy), NULL);

/* Création de bouton
bouton[0]=gtk_button_new_with_label("Instruction");
bouton[1]=gtk_button_new_with_label("Jouer");
bouton[2]=gtk_button_new_with_label("Résoudre");
bouton[3]=gtk_button_new_with_label("Annuler");
*/
vbox=gtk_vbox

grid=gtk_grid_new();
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);

gtk_container_add(GTK_CONTAINER(p_window),grid);

/********** Menu *************/
barre_menu=gtk_menu_bar_new();
menu=gtk_menu_new();

sous_menu_fichier=gtk_menu_item_new_with_label("Fichier");

for(i=0;i<4;i++)
{
  GtkWidget *sous_menu = gtk_menu_item_new_with_label(tableau[i]);
  gtk_menu_shell_append(GTK_MENU_SHELL(menu),sous_menu);
  g_signal_connect(sous_menu,"activate",G_CALLBACK(menu_cb),NULL);
}

gtk_menu_item_set_submenu(GTK_MENU_ITEM(sous_menu_fichier),menu);
gtk_menu_shell_append(GTK_MENU_SHELL(barre_menu),sous_menu_fichier);

gtk_grid_attach(GTK_GRID(grid),barre_menu,0,0,1,1);

gtk_widget_show_all(p_window);

gtk_main();
return 0;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group