Hi,
Take a look at your modified example:
[code]#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
class MyMainFrame : public TGMainFrame {
private:
TCanvas *fCanvas;
public:
MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MyMainFrame();
void ToggleToolbar();
void ToggleStatusbar();
};
MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) :
TGMainFrame(p,w,h)
{
// this is where the actual embedding is done
SetEditable();
fCanvas = new TCanvas(“Foo”, “Bar”, w, h);
SetEditable(kFALSE);
TRootCanvas *rc = (TRootCanvas *)fCanvas->GetCanvasImp();
// remove (hide) the menu bar
TGFrameElement *el = 0;
TIter next(rc->GetList());
while ((el = (TGFrameElement *)next())) {
if (el->fFrame->InheritsFrom(“TGMenuBar”)) {
TGMenuBar *mb = (TGMenuBar *)el->fFrame;
TGCompositeFrame *cf = (TGCompositeFrame *) mb->GetParent();
if (cf) cf->HideFrame(mb);
break;
}
}
// Create a horizontal frame widget with buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(this,200,40);
TGTextButton *toolbar = new TGTextButton(hframe,"&ToolBar");
toolbar->Connect(“Clicked()”,“MyMainFrame”,this,“ToggleToolbar()”);
hframe->AddFrame(toolbar, new TGLayoutHints(kLHintsCenterX, 5,5,3,4));
TGTextButton *statusbar = new TGTextButton(hframe,"&StatusBar");
statusbar->Connect(“Clicked()”,“MyMainFrame”,this,“ToggleStatusbar()”);
hframe->AddFrame(statusbar, new TGLayoutHints(kLHintsCenterX, 5,5,3,4));
AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2,2,2,2));
// Set a name to the main frame
SetWindowName(“Simple Example”);
// Map all subwindows of main frame
hframe->MapSubwindows();
hframe->MapWindow();
Layout();
// Initialize the layout algorithm
Resize(GetDefaultSize());
// Map main frame
MapWindow();
}
void MyMainFrame::ToggleToolbar() {
// Toggles the toolbar
fCanvas->ToggleToolBar();
Layout();
cout << "Tool bar: " << fCanvas->GetShowToolBar() << endl;
}
void MyMainFrame::ToggleStatusbar() {
// Toggles the toolbar
fCanvas->ToggleEventStatus();
Layout();
cout << "Status bar: " << fCanvas->GetShowEventStatus() << endl;
}
MyMainFrame::~MyMainFrame() {
// Clean up used widgets: frames, buttons, layout hints
Cleanup();
}
void canvasError() {
// Popup the GUI…
new MyMainFrame(gClient->GetRoot(),600,400);
}
[/code]
Cheers, Bertrand.