Overriding closeButtonPressed event so JUCEApplication is minimized instead of getting closed


I’m trying to implement minimization of an application when ‘X’ button is being pressed from the toolbar (on both Mac & Windows platforms).
I see that closeButtonPressed() method is being called as a result of any application closure flow, without any clear way to override/filter the exact action being taken for closure. I want to filter out the toolbar close button pressing from the other terminating actions and call setMinimised(true) instead.

Thanks in advance,

If you’re not using the native title bar in your application then you can use the DocumentWindow::getCloseButton() method to add a listener to the button that is returned and then minimise your window in the buttonClicked() callback.


Hi Ed,

Thanks for answering. I’ve tried that already. The pointer I get is always Null for some reason. It seems impossible to use getCloseButton() for this purpose. By the way, while doing that I saw that JUCE throws an assertion when trying to register as a listener to buttons from a DocumentWindow-derived object.


Are you using the native title bar? The DocumentWindow only returns a valid pointer to a Button object if you’re using JUCE’s title bar otherwise it will return nullptr. Try calling setUsingNativeTitleBar (false) in the constructor of your DocumentWindow subclass.


I tried to use setUsingNativeTitleBar (false) and it is working indeed. Why does it work like this? I want to use the native title bar and still get the close button event.