TCanvas *canvas[4]; Bool_t cState[4] = {kFALSE,kFALSE,kFALSE,kFALSE}; void SetBackground(TObject *canv); Bool_t GetBackground(TObject *canv); void AddToggleToContext(){ TClass *cl; TList*l; TClassMenuItem* mi; char name[20]; for(int n=0;n<4;n++){ //make 4 canvases names "MyCanvas_0,1,2,3" sprintf(name,"MyCanvas_%d",n); canvas[n] = new TCanvas(name,name,n*100,0,100,100); } //add the menu item as illustrated in tutorial $ROOTSYS/tutorials/gui/customContextMenu.C cl = canvas[0]->IsA(); cl->SetContextMenuTitle("Modified TCanvas Context Menu"); l = cl->GetMenuList(); mi = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Set Background","SetBackground",0,"TObject *",0); //mi->SetToggle(); //menu item doesn't appear if I comment this in l->AddFirst(mi); } void SetBackground(TObject *canv){ int index; sscanf(canv->GetName(),"MyCanvas_%d",&index); //Get the index from the object name cState[index]=!cState[index]; //toggle the state canvas[index]->SetFillColor(cState[index]); //set the fill color canvas[index]->Draw(); canvas[index]->Update(); } Bool_t GetBackground(TObject *canv){ int index; sscanf(canv->GetName(),"MyCanvas_%d",&index); //Get the index from the object name return cState[index]; //return the state }