Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Program Onclosing.

Hey.

The program onclose event works when i close the program.
But when windows closes it or taskmanager then it won't use the onclose event.
How can you set an event on windows closes or taskmanager.

Thanks.
0
JuiceJJ
Asked:
JuiceJJ
  • 2
1 Solution
 
geobulCommented:
Hi,

About Windows shutdown:

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMQueryEndSession(var Message: TMessage);
begin
  // do your stuff here
  Message.Result := Integer(true);
end;

Regards, Geo
0
 
geobulCommented:
Forgot to say that TForm1 is your main form. The code above is for your main form only.

When I close an app with the Task manager (Windows XP) then my form's OnClose event gets called.

Regards, Geo
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
why don't use the OnCloseQuery event?
It's called when message WMQueryEndSession is received by the form...
and there you can also reject the closure setting canclose to false

F68 ;-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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