[Lazarus] capturing system shutdown

JoshyFun joshyfun at gmail.com
Sun Dec 20 23:31:07 CET 2009


Hello Lazarus-List,

Monday, December 21, 2009, 6:01:28 AM, you wrote:

CJ> 1. User opens my program and begins to interact with the data behind the
CJ> program.
CJ> 2. User initiates a system shutdown or logoff without closing my program.
CJ> 3. The system must transfer control to my program that will at this
CJ> point bring up a dialog suggesting that the user save any changes and
CJ> close the program.
CJ> 4. Upon doing #3, the system then continues with shutdown or will acept
CJ> a new shutdown command.
CJ> I know that this can be accomplished but have now idea where to start.

In Windows world you must handle the WMQueryEndSession message, I had
done it in Delphi in the past but never in Lazarus. You can try this
Delphi snippet http://delphi.about.com/cs/adptips2000/a/bltip0500_4.htm

Take care that if you show the message but do not answer or cancel the
shutdown the system will anyway shutdown thinking that your
application is hanged. So the process should be like:

1) Handle message
2) Message is being received
3) Post a message or setup a timer to happend 100 ms after to
   show the custom message.
4) Answer to message cancelling the shutdown.
5) If you decide to continue with shutdown invoke a programatically
   system shutdown.

-- 
Best regards,
 JoshyFun





More information about the Lazarus mailing list