Adding to menu bar

hello
in my c++ standalone program i have a TCanvas that contains several objects, like TPads etc. now i want to add a popupmenu (TGPopupmenu, i guess) to the menu bar on top of the TCanvas.
does anyone know how this can be done?

i’m using root 5.11/06.

zimmi

[quote]
in my c++ standalone program i have a TCanvas that contains several objects, like TPads etc. now i want to add a popupmenu (TGPopupmenu, i guess) to the menu bar on top of the TCanvas.
does anyone know how this can be done?

i’m using root 5.11/06.

zimmi[/quote]

Try embedded canvas. In gui test ($ROOTSYS/tutorials/guitest.C) there is an example of usage - it’s embedded into dialog, but you can simply convert this into TGMainFrame_descendant + TRootEmbeddedCanvas.

PS. Or you can modify you TRootCanvas to add new menu :slight_smile:)

[quote=“tpochep”]
Try embedded canvas. In gui test ($ROOTSYS/tutorials/guitest.C) there is an example of usage - it’s embedded into dialog, but you can simply convert this into TGMainFrame_descendant + TRootEmbeddedCanvas.

PS. Or you can modify you TRootCanvas to add new menu :slight_smile:)[/quote]

thanks for answering. so there is no way to do it with TCanvas?

if not i will try, what you recommended.

Hi,
as far as I understood the question the following code must help:

   TCanvas *canvas = new TCanvas();
   TRootCanvas *imp = (TRootCanvas*)canvas->GetCanvasImp();
   TGMenuBar *bar = imp->GetMenuBar();
   TGPopupMenu *popup = bar->AddPopup("my popup");
   popup->AddEntry("1st entry", 1);
   popup->AddEntry("2nd entry", 2);
   bar->MapSubwindows();
   bar->Layout();

Regards. Valeriy

thanks valeriy, i will try this. tried something similar, but could’t get it to work so far. i think your code will help.

update: that works perfectly. thanks again. just for better understanding:
what does these two lines do:
bar->MapSubwindows();
bar->Layout();
?

map/display a new popup entry on the screen

move a new popup entry to the “right” position inside menu bar