MessageProcess question

Hi,

I started from the simple gui example which uses the MessageProcess method:
root.cern.ch/root/hepvis98/newgui.html
then I wanted to add to it Tabs.

The problem that I have now, is that the MessageProcess works only when with the mouse, i switch from one Tab to the other.
No message is printed out if in one of these two tabs, I select one of the two buttons.

Shall I create my own classes for each of the two Tab objects and define a MessageProcess Method for each of these two objects, or is there a much faster solution?

In advance, thanks for your valuable help.
Ps: find below the program, which compiles well.

// mymain.cxx code
#include “mymain.h”
#include <iostream.h>

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{

TabFrame = new TGTab(this, w, h);
fLayoutTabFrame = new TGLayoutHints(kLHintsExpandX|kLHintsCenterX,2,2,2,2);
AddFrame(TabFrame,fLayoutTabFrame);

TabFrame1= TabFrame->AddTab("-1-");
fButtonExit = new TGTextButton(TabFrame1, “&Exit”,2);
fLayoutTab1 = new TGLayoutHints(kLHintsExpandX|kLHintsCenterX,2,2,2,2);
TabFrame1->AddFrame(fButtonExit, fLayoutTab1);

TabFrame2= TabFrame->AddTab("-2-");
fChkButton = new TGCheckButton(TabFrame2, “Check Button”, 4);
fLayoutTab2 = new TGLayoutHints(kLHintsExpandX|kLHintsCenterX,2,2,2,2);
TabFrame2->AddFrame(fChkButton, fLayoutTab2);

MapSubwindows();

Layout();

SetWindowName(“Button Example”);
SetIconName(“Button Example”);

MapWindow();
}

Bool_t MyMainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
cout << “In Process Message” << endl;
return kTRUE;
}

// mymain.h file
#include <TGClient.h>
#include <TGButton.h>
#include <TGTab.h>
class MyMainFrame : public TGMainFrame {

private:
TGTab *TabFrame;
TGCompositeFrame *TabFrame1;
TGCompositeFrame *TabFrame2;

TGTextButton *fButtonExit, *fButtonVersion;
TGCheckButton *fChkButton;
TGLayoutHints *fLayoutTabFrame;
TGLayoutHints *fLayoutTab1;
TGLayoutHints *fLayoutTab2;

public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
~MyMainFrame() { } // need to delete here created widgets
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
// File: main.cxx

#include <TApplication.h>
#include <TGClient.h>
#include “mymain.h”

int main(int argc, char **argv)
{
TApplication theApp(“App”, &argc, argv);
MyMainFrame mainWin(gClient->GetRoot(), 800, 800);
theApp.Run();
return 0;
}

Hi Nabil,
to be able ProcessMessage from buttons
you need to call TGWidget::Associate method, e.g.

fButtonExit->Associate(this); // where this is MyMainFrame object

HTH. Regards. Valeriy

Hi,
thanks it’s perfectly working!