Board index » delphi » How can application detect windows shutdown?

How can application detect windows shutdown?

When an application is told to close due to impending Windows shutdown, is
there a way for the application to determine that this is the reason for
shutdown, as opposed to someone clicking on the close icon on the form's
title bar?
 

Re:How can application detect windows shutdown?


Trap the WM_QUERYENDSESSION message that windows sends before
shutdown. Look for it in win32.hlp.

Quote
Greg Jackson wrote in message <#4MfSEHK#GA.274@upnetnews03>...
>When an application is told to close due to impending Windows
shutdown, is
>there a way for the application to determine that this is the reason
for
>shutdown, as opposed to someone clicking on the close icon on the
form's
>title bar?

Re:How can application detect windows shutdown?


Quote
>   "Scott Roberts" <sgrob...@nospam-iamerica.net> writes:
>  Trap the WM_QUERYENDSESSION message that windows sends before
>  shutdown. Look for it in win32.hlp.

>  Greg Jackson wrote in message <#4MfSEHK#GA.274@upnetnews03>...
>  >When an application is told to close due to impending Windows
>  shutdown, is

I am using this to put my program in the registry so it automatically opens again when windows is restarted.
(Sorry for swedish comments!)

//========= Detta k?rs om windows st?nger programmet. (Endast fria) ===================//
procedure tmditted.WMEndSession (var msg : TWMEndSession);
var
  reg : tregistry; //F?r att kunna komma ?t registret
begin
  reg := tregistry.create; //Skapa en koppling till registret
  try
    reg.rootkey := HKEY_CURRENT_USER; //V?lj grundnyckel
    if reg.openkey ('\Software\Microsoft\Windows\CurrentVersion\Runonce',true) then //Om det g?r att ?ppna denna
       reg.writestring ('TTSGMLED','"'+paramstr(0)+'"'); //S? skriv in ttsgmled
       //Detta g?r att ttsgmled startas automatiskt n?r man startar om windows
  finally
    reg.closekey;   //St?ng nyckeln
    reg.free; //Frig?r registerkopplingen
    inherited; //K?r resten av de inbyggda rutinerna
  end;
end; //WMEndSession

johan

Other Threads