BBC BASIC for Windows
« Detecting that the window has been closed »
Welcome Guest. Please Login or Register. Apr 5th, 2018, 10:28pm
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
If you require a dump of the post on your message board, please come to the support board and request it.
Detecting that the window has been closed
« Thread started 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.
Logged
Zaphod Guest
Re: Detecting that the window has been closed
« Reply #1 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.
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.