Close Event

Zenerdiode

Active Member
Licensed User
In the Form1_Close Sub, I'd like to be able to know if the event was fired by the AppClose keyword, the user clicking the red 'X' button or whether Windows is shutting down and has sent it a WMClose message. I'd then be able to process the close request accordingly.
 

RandomCoder

Well-Known Member
Licensed User
You need to set a global variable eg ShutDown and initially set it to False.
Just before you use AppClose set ShutDown to True.
Also do this if the WM has been detected.
In the Close event check whether ShutDown is true or false and action accordingly.

Regards,
RandomCoder.
 

mjcoon

Well-Known Member
Licensed User
..
Also do this if the WM has been detected.
Regards,
RandomCoder.
How would you distinguish WMClose?

And in my experiments I didn't think I got Form1_Close if the user was clicking on an "X" to hide (rather than "OK" to close).

Mike.
 

RandomCoder

Well-Known Member
Licensed User
How would you distinguish WMClose?
You can catch WM_Messages using DZT's library found here http://www.basic4ppc.com/forum/additional-libraries/748-dzeventsmagic.html (WM_Close = 16)

And in my experiments I didn't think I got Form1_Close if the user was clicking on an "X" to hide (rather than "OK" to close).
If setting the Form to minimize then you need to provide another way of closing the Form eg menu option or button.

regards,
RandomCoder
 

mjcoon

Well-Known Member
Licensed User
If setting the Form to minimize then you need to provide another way of closing the Form eg menu option or button.
RandomCoder
Sure, have done that, and don't need to capture an event for something initiated by the program itself. But it could be useful to know if the program has been hidden. I'll look at that events library, thanks.

Mike.
 
Top