• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

catching "windows shutdown"

how do i make an application that triggers and event when a user tries to shutdown windows?
0
dabestprogrammerindauniverse
Asked:
dabestprogrammerindauniverse
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
windows send WM_QUERYENDSESSION message to the application running when it's trying to shutdown
0
 
Mohammed NasmanSoftware DeveloperCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMQueryEndSession(var Msg : TWMQueryEndSession); message WM_QueryEndSession;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMQueryEndSession(var Msg : TWMQueryEndSession);
begin
  if MessageDlg('Close Windows ?', mtConfirmation, [mbYes,mbNo], 0) = mrNo then
    Msg.Result := 0
  else
    Msg.Result := 1;
end;


end.
0
 
PeterLarsenCommented:
There are two messages you should be aware of :
   procedure wmQueryEndSession(var msg:TMessage); message WM_QUERYENDSESSION;
and
   procedure WMENDSESSION(var msg:TMessage); message WM_ENDSESSION;

Regards
Peter
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Dennis9Commented:
Try this:

procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;

procedure TMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
Handled := False;
if Msg.message = WM_QUERYENDSESSION then
begin
Showmessage('Windows are about to close');
end;
Handled := false;//If u set it to true it will close
end;


Dennis
0
 
karouriCommented:
da best solutions in da universe have already been offered;)
0
 
dabestprogrammerindauniverseAuthor Commented:
thanks everyone!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now