Solved

catching "windows shutdown"

Posted on 2001-09-07
6
192 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
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!

 
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

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!

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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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