Solved

catching "windows shutdown"

Posted on 2001-09-07
6
190 Views
Last Modified: 2010-05-18
how do i make an application that triggers and event when a user tries to shutdown windows?
0
Comment
6 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6463396
windows send WM_QUERYENDSESSION message to the application running when it's trying to shutdown
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 6463401
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
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 6463624
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:Dennis9
ID: 6463745
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
 
LVL 3

Expert Comment

by:karouri
ID: 6468546
da best solutions in da universe have already been offered;)
0
 

Author Comment

by:dabestprogrammerindauniverse
ID: 6469402
thanks everyone!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question