We have introduced a new event OnWindowCloseQuery but it is not yet documented.
How do I ask users if they are sure they want to close the main window?
Use HEScript scripting and a dedicated event in UserMain (OnWindowCloseQuery):
For instance, use this HEScript function in your UserMain script.
function OnWindowCloseQuery (WindowName: String): Boolean;
Result := True;
if MessageBox("Do you really want to close this window?",
"Confirmation", MB_YESNO+MB_ICONWARNING) = IDNO then Result := False;
Don’t use OnCloseWindow to prevent the program from closing the window. When this event is fired, the program is going to exit.
Actually, I was using it when the user clicks on the red X of the main window only. This allowed me to run a routine before executing the program with ExitPublication.
It probably wouldn’t hurt to have them confirm to exit the program. A variable could be set to show or hide the confimation message.
In version 4.7, the way the program is looping, It’s like the OnWindowClose keeps firing. The message box is above the ExitPublication but never executes and exits, as it did before. You get into a loop of constantly seeing the message box keep coming up. In the routine, there are no loops, just a if else and everything works as expected except exiting the program. At that point, the only to exit is to abort it in the Task Manager.
I will give the OnWindowCloseQuery and see if that works and will let you know.