Block the 'Closed()' signal of TCanvas


Is there a simple way to block the ‘Closed()’ signal of TCanvas? My purpose is protecting Canvas being closed by the ‘Close’ button on the up-right corner.

I know a method for this purpose is connect the ‘Closed()’ signal to a user slot (such as can->Connect(“Closed()”,“MTree”,this,“ClosedCanvas()”);). However this way is not good for me, because I used the ‘ProcessMessage()’ method to implement my program.

The ‘BlockAllSignals()’ method of ‘TCanvas’ is also not good, because it disabled the ‘MenuBar’ signals also.

Is there some other ways?

Any reply is appreciated.


Hi Han,

You can avoid closing the canvas by calling the DontCallClose() method, but then, it is up to you to close it. The code would look like this:

Another solution could be to tell the window manager to not close the canvas:

((TRootCanvas *)canvas->GetCanvasImp())->SetMWMHints(kMWMDecorAll, kMWMFuncResize | kMWMFuncMaximize | kMWMFuncMinimize | kMWMFuncMove, kMWMInputModeless);
But as it is highly WM (window manager) dependent, this may not work (e.g. it does not work on Windows)

Cheers. Bertrand.

Hi Bertrand,

Thank you very much.
I choose the first method, it works well under both Windows and Linux.