CancelClose: Good with close-Fail with hide?

Hello everyone,

Is CancelClose supposed to work with hidden windows or only closed windows? Is this a ‘Works as expected’ aspect with CancelClose or a bug? Here is an example:

When using CancelClose to ask the user if they ‘really want to leave the program’, the event works well as long as there is only one window open and all other windows closed. CancelClose will close the window and not cancel (leaves program running in background on Windows) if there is a window that has the window.hide transition. The following project shows how the Window.hide causes an issue on Windows 10 Technical Preview.

CancelClose Project

To have CancelClose work properly in the program, change the two action button codes from close to hide:


Window2.Show Window1.Hide


Window2.Show Window1.Close

…and perform the same hide->close change with the pushbutton on Window2.

Is this expected or a bug? Thank you.

App.CancelClose has nothing to do with how many windows are open, hidden, or not. You should use the Window.CancelClose event for window dependent cancelling.

CancelClose allows you to keep a window from being closed. This is not a bug.

Thank you for the comments.

In the App.CancelClose event, there is a message box to allow the user to check if they want to close the program. I believe the App.CancelClose event should prevent the app from closing?

My guess (which could be wrong) is that having multiple windows hidden and calling the App.CancelClose event will likely cause some hidden windows to close but will keep one window open?

Thanks for your patience :slight_smile:

Every window, hidden or not, gets the cancelclose event raised

If you return true then you can cancel closing the window

The issue you’re running into is with “closing a window” vs. “closing the application”. There is a setting (or used to be, I can’t find it in the new IDE) on Windows for “close the application when the last window closes”. This should default to on for Windows and off for Mac, as that is the correct sense for each platform. The problem is that when you Hide the window, calling window.close on the other window closes that window, but it isn’t the “last man standing”, so the app doesn’t close, due to the existence of the other window which is still open, but hidden. Your app is now effectively running in the background. This is really a coding error under windows where you have allowed a window to remain open but hidden. You should either

  1. Detect a hidden window and show it again, or
  2. Change your close button from window.close to Quit, to force the app to close

This is called AutoQuit.

Excellent Tim - you nailed it! Thank you, and I’ll change the code so that every window will be closed instead of hidden.

Thank you Bob, this is a great help.