Solved

catching "windows shutdown"

Posted on 2001-09-07
6
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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