我想在我的程序退出时,给用户提示:"程序退出了"正常操作是关闭窗体Form1.close 或者 Application.Terminate,这样FormDestroy完全可实现提示用户.
但是当用户在"任务管理器里结束进程时",就没有消息提示了.(据说HOOK可以实现,但是找了几个方法,还是无法获取关闭消息)
恳请各路大人帮帮忙,谢谢!unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  TForm1 = class(TForm)
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  HookHandle: HHOOK;
function CloseHookProc(Code: Integer; WParam: WParam; Msg: LongInt): LRESULT; stdcall;implementation{$R *.dfm}function CloseHookProc(Code: Integer; WParam: WParam; Msg: LongInt): LRESULT; stdcall;
begin
  if Code = HC_ACTION then
    if PMsg(Msg)^.message = WM_close then
    begin
      Application.MessageBox('程序关闭了!', '提示', MB_OK);
      PMsg(Msg)^.message := 0; //拦截消息窗体关闭消息
      Result := 0; //不把消息传出去
    end
    else
      Result := CallNextHookEx(HookHandle, Code, WParam, Longint(@Msg));
end; //钩子回调函数procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.MessageBox('程序关闭了!', '提示', MB_OK);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  HookHandle := SetWindowsHookEx(WH_CALLWNDPROC, CloseHookProc, HInstance, GetCurrentThreadID); //钩住自己的主窗
end;end.