[ROOT] ProcessMessage() is never called?

From: Olivier D'Arcy (darcy@ligo.mit.edu)
Date: Fri Jun 02 2000 - 23:31:03 MEST


Hi, I'm trying to run the following simple GUI example in order to
understand how does the function ProcessMessage() work. I read that when a
button is pressed, the message (kC_COMMAND, kCM_BUTOON,button_id,...) is
sent and when an item from the listbox is selected, the message
(kC_COMMAND, kCM_LISTBOX, listbox_id, item_id) is sent. Still the
ProcessMessage() of the following code is never called even if I press
one of the button or click an item in the list box. Why? 

within root: 
I link the file with .L ~/.../...
then I type main()

code:
class MyMainFrame : public TGMainFrame {

private:
    TGTextButton    *fButton1, *fButton2;
    TGLayoutHints   *fLayout;
    TGListBox	    *fListbox;

public:
    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
    ~MyMainFrame();
    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};

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


// set the cmd string, cmd is a string that calls the processmessage
method when any of the button is called
	
	char cmd[128];
	sprintf(cmd, "{long r__ptr=0x%x;
((MyMainFrame*)r__ptr)->ProcessMessage($MSG,$PARM1,$PARM2);}", this);

    fLayout = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY);
    
    fButton1 = new TGTextButton(this, "&Version", 1);
    AddFrame(fButton1, fLayout);
    fButton1->Associate(this);
    
    fButton2 = new TGTextButton(this, "&Exit", 2);
    AddFrame(fButton2, fLayout);
    fButton2->Associate(this);
    
    
    fListBox = new TGListBox(this, 3);
    fListBox->Associate(this);
    AddFrame(fListBox, fLayout);
    fListBox->Resize(180,200);		
    fListBox->AddEntry("entry 1", -1 );
    fListBox->AddEntry("entry 2", -1 );
    fListBox->AddEntry("entry 3", -1 );
    fListBox->AddEntry("entry 4", -1 );
    fListBox->MapSubwindows();
    fListBox->Layout();
		

    MapSubwindows();


    SetWindowName("Listbox test");
    Resize( GetDefaultSize());

    MapWindow();
}

MyMainFrame::~MyMainFrame()
{
	delete fListBox;
	delete fButton2;
	delete fButton1;
	delete fLayout;
}

Bool_t MyMainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
    // Process events generated by the buttons in the frame.
	cout<<"entering processmesg"<<endl;
	
    switch (GET_MSG(msg)) 
    {
        case kC_COMMAND:
        cout<<"entering kcCommand switch"<<endl;
            switch (GET_SUBMSG(msg))
            {
                case kCM_BUTTON:
                    printf("text button id %ld pressed\n", parm1);
                    break;
                case kCM_LISTBOX:
                    printf("item id %ld selected from listbox id %ld \n",
parm2, parm1);
                    break;
                default:
                    break;
            }
        default:
            break;
    }
    return kTRUE;
}


void main() 
{ 
 	mainWin = new MyMainFrame(gClient->GetRoot(), 600, 600);
}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET