Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing user from closing program

Status
Not open for further replies.

dmarsh3

Programmer
Oct 15, 2004
1
GB
I am trying to prevent users from closing my program unless they were logging off or shutting down by trapping the windows WM_QUERYENDSESSION message - unfortunatly I have a few users that are reasonably intelligent & have worked out that if you load up word, type something into the editor & then try to log off, windows sends the QueryEndSession message to all windows so my app closes, but word asks if the user wants to save before it lets windows log off, the user then just clicks cancel in word & the computer stays logged on and working with my app shutdown... Anyone know of a way around this?

Thanks

 
You could write a service application (or normal program with a hidden window), and both have an idle thread that monitors the existence of the other program. As soon as they detect the other being closed, it re-runs it.
 
Perhaps a different approach would be to acknowlege the WM_QUERYENDSESSION and "approve" it, but not "close" the program until you see the WM_ENDSESSION message.

However, there is an article that states that "..Delphi does not process the WM_ENDSESSION" correctly and offers some advice.




Regards and HTH,
JGS
 
You could try the following

in the OnClose form Event

Code:
if closeMyApp = y then // some check statement
action := caFree else  // if true then close
action := caNone;      // if not then return to App

Hope this helps, I use it for when users click the cross, to ask them and then close everything properly.



Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top