How to trap mouse middle button clicks on a Histogram in a TCanvas

TRAPPING MOUSE MIDDLE BUTTON CLICKS ON A HISTOGRAM IN A TCanvas

I have a window in which I have a TCanvas embedded in a TRootEmbeddedCanvas.
I then draw a histogram using TH1I in the TCanvas.
Now my software is a standalone executable using ROOT libraries and
also has the following function where the window messages are processed :
Bool_t HistWin::ProcessMessage (Long_t msg, Long_t parm1, Long_t parm2)
Now I want to trap the mouse middle button clicks made on the histogram
and want to capture the index i.e the x-axis value of the point and
print the corresponding y-axis value.
I had a look at the files :
1.root/tutorials/gui/exec3.c
2.root/tutorials/hist/exec2.c
3.root/tutorials/hist/exec1.c
I could not locate the corresponding demo file. #-o
I tried to understand it to incorporate the code in my program without much progress. #-o
I guess I need help to make progress. :confused:

See:



Hi, I made some progress as can be seen by running attached code.
BUT now a new problem : after closing the histogram window if i re-open it again and then if I CLICK the middle button then the following error messages appear :

Error in : BadDrawable (invalid Pixmap or Window parameter) (TGCompositeFrame XID: 71303530, XREQ: 62)
TGCompositeFrame: 71303530
TGViewPort: 71303521
TRootEmbeddedCanvas: 71303520
TGVerticalFrame: 71303519
TGCompositeFrame: 71303518
HistWin: 71303564
Error in : BadWindow (invalid Window parameter) (TGCompositeFrame XID: 71303530, XREQ: 2)
TGCompositeFrame: 71303530
TGViewPort: 71303521
TRootEmbeddedCanvas: 71303520
TGVerticalFrame: 71303519
TGCompositeFrame: 71303518

To compile attached code do as follows:

  1. make clean
  2. make dict
  3. make
  4. ./nscope to run the code

Kindly teach how to debug such error messages , can gdb be used ? or any other ? like ddd ?
or any other debugging method kindly suggest so I can debug on my own.
Help and guidance greatly appreciated. THANKS VERY MUCH.
nscopeIJuly2015.tar.gz (16.5 KB)

Hi,

You should add: delete fRootEmbeddedCanvas799;in the destructor (TRootEmbeddedCanvas is not properly deleted by the Cleaup() method).
And you can use gdb, or your preferred debugger to debug your application…

Cheers, Bertrand.

Hi,
The code was still crashing sometimes when the HistWin window was closed.
So I added the line as follows and now it is much more stable:

In Destructor

if (fRootEmbeddedCanvas799)
delete fRootEmbeddedCanvas799;
}

Thank you Bertrand for solving my problem.
Cheers, Abraham