Prohibiting destruction of TGWindow by window buttons

Hello,

I am trying to prevent the destruction of a dialogue so that I can keep track of it easily for the duration of an application’s run time. This allows me to prevent multiple copies of it from existing and being able to provide a reliable reference/pointer to other dialogues that might want to interact it. I see that I could accomplish this using the Signal/Slot mechanism by connecting the CloseWindow signal of the dialogue to an event handler in the TGMainFrame that manages the dialogue’s existence, but the application I’ve inherited was already written using the ProcessMessage event handling scheme. To keep things consistent and simpler for those who will maintain this application in the future, I want to avoid using multiple types of event handling and thereby the Signals/Slot mechanism.

Is there any way to inform the TGMainFrame when the close window button (eg. at the very top left of the window in Ubuntu or at the very top right of the window in Windows) is pressed in this scheme? I ultimately don’t want the window to be deleted when this button is pressed, but rather the UnmapWindow method called.

Thank you in advance.

Hi,

You should try to use the TGMainFrame:DontCallClose() method to not close it. And then, the only way to get the “CloseWindow()” notification is via signal/slot (it comes for free anyway, and you can simply set a flag in your class). If it doesn’t help, feel free to post a running piece of code illustrating what you’re trying to do and where it fails.

Cheers, Bertrand.

Bertrand,

Thank you for your prompt reply. As far as I can tell, this seems to have accomplished the desired goal. Unfortunately, the close window button is now superfluously present and does nothing when pressed.

We can likely live with its presence for the moment, but in the future, would it be possible to remove the display of this button when the TGMainFrame::DontCallClose is called?

Thanks again,
Jeromy

Hi Jeromy,

[quote=“jrtomps”]Thank you for your prompt reply. [/quote]You’re welcome.

[quote=“jrtomps”]We can likely live with its presence for the moment, but in the future, would it be possible to remove the display of this button when the TGMainFrame::DontCallClose is called? [/quote]Well, I don’t really want to try to remove the buttons by default (some people still want to be notified and have full control when user press the close button). But you can try to do it yourself by calling the TGMainFrame::SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input); method to try to remove the button. But note that this is highly platform/Window Manager dependent, and it may fail (I just tried on Windows and I can remove all but the close button…)

Cheers, Bertrand.

Bertrand,

I respect your desire ensure portable functionality. My application will only be running on very similar Linux computers so that it is probably okay to remove the button. If it turns into a problem, I know now the TGMainFrame::DontCallClose() method.

After playing around with the options, I have successfully achieved what I wanted for my windows by adding the following lines to the dialogue’s constructor:

    SetMWMHints(kMWMDecorBorder|kMWMDecorTitle,
                kMWMFuncResize|kMWMFuncMove, 0);

There is now no call to the DontCallClose() method. I had to play around a bit with the options to get what I wanted and am curious to know if you tried this recipe on the Windows computer you were working on earlier.

Jeromy

Hi Jeromy,

Yes, this removes everything, Thanks! But as soon as one adds “kMWMDecorMenu”, the close button re-appears… Anyway, glad to see you solved your issue!

Cheers, Bertrand.