截获WM_QUERYENDSESSION消息,并返回1 TForm1 = class(TForm) private procedure WMQUERYENDSESSION(var msg:Tmessage);message WM_QUERYENDSESSION; { Private declarations } public { Public declarations } end;procedure tform1.WMQUERYENDSESSION(var msg:Tmessage); begin msg.Result :=1; end;
终于找到了: var willcolse:boolean;//授权“关闭”变量,你可以保存到INI文件或注册表中。procedure mymessage(var Message: TWMSysCommand);message WM_SYSCOMMAND;procedure TForm1.mymessage(var Message: TWMSysCommand); begin if (Message.CmdType and $FFF0 = SC_CLOSE) then if willcolse then Inherited else Application.Minimize else Inherited; end;procedure TForm1.FormCreate(Sender: TObject); begin willcolse:=true;//授权“关” end;procedure TForm1.Button1Click(Sender: TObject); begin willcolse:=false;////授权“不关” end;
TForm1 = class(TForm)
private
procedure WMQUERYENDSESSION(var msg:Tmessage);message WM_QUERYENDSESSION;
{ Private declarations }
public
{ Public declarations }
end;procedure tform1.WMQUERYENDSESSION(var msg:Tmessage);
begin
msg.Result :=1;
end;
var willcolse:boolean;//授权“关闭”变量,你可以保存到INI文件或注册表中。procedure mymessage(var Message: TWMSysCommand);message WM_SYSCOMMAND;procedure TForm1.mymessage(var Message: TWMSysCommand);
begin
if (Message.CmdType and $FFF0 = SC_CLOSE) then
if willcolse then Inherited
else Application.Minimize
else Inherited;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
willcolse:=true;//授权“关”
end;procedure TForm1.Button1Click(Sender: TObject);
begin
willcolse:=false;////授权“不关”
end;
interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus,AppEvnts,shellapi;
type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
ApplicationEvents1: TApplicationEvents;
PopupMenu1: TPopupMenu;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Btn_OK: TButton;
Btn_Abort: TButton;
procedure Timer1Timer(Sender: TObject);
procedure TrayMenu(Var Msg:TMessage); message WM_USER;
procedure TimeSetClick(Sender: TObject);
procedure ExitClick(Sender: TObject);
procedure Btn_OKClick(Sender: TObject);
procedure Btn_AbortClick(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure WMQueryEndSession (var Msg : TWMQueryEndSession);
message WM_QueryEndSession;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
Tray:NOTIFYICONDATA;
procedure ShowInTray();
public
{ Public declarations }
end; var
Form1: TForm1;
P,Ti1:Pchar;
Flags:Longint;
i:integer;
{关机延迟时间}
TimeDelay:integer;
atom:integer;
implementation
{$R *.dfm}