BBC BASIC for Windows
Programming >> User Interface >> Detecting that the window has been closed
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1457875133

Detecting that the window has been closed
Post by simong42 on Mar 13th, 2016, 1:18pm

Next question :
I'm writing a program which will enable the user to design mazes, editing it with mouse clicks.
If the user clicks on the X button in the top-right corner, this ends the program - which is normally what I'd want.
However, in this case, there may be unsaved changes.

Is there any way of detecting the 'X' being clicked, so that I can put up an 'are you sure?' dialogue.
Re: Detecting that the window has been closed
Post by Zaphod on Mar 13th, 2016, 1:51pm

The answer is yes.
If we are talking about the main window or non-dialog windows then there is the ON CLOSE event which is designed to give you a chance to do something as the window is about to close.
If it is a dialog window then a WM_COMMAND message with an @wparam% value of 2 will be generated. To be able to trap that you will have to use WINLIB2B as WINLIB2 does not pass that onto the user but closes the dialog window automatically. With WINLIB2B the user has to close the dialog window after detecting the 2.

Here are some references that may help.
http://bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#onclose
Quote:
The WINLIB2B library contains an identical set of functions but additionally forwards to your program any WM_HELP and WM_NOTIFY messages generated by the dialogue box controls. These messages can be intercepted using *SYS 1 to allow your program to provide, for example, context-sensitive help for your dialogue box. WINLIB2B also suppresses the automatic closing of the dialogue box when you click on its close button, or press Escape.

Re: Detecting that the window has been closed
Post by simong42 on Mar 16th, 2016, 4:05pm

Thanks, ON CLOSE is what I'm after for the main window