var
hSysMenu: HMENU;hSysMenu := GetSystemMenu( Form.Handle, FALSE );
EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED );
hSysMenu: HMENU;hSysMenu := GetSystemMenu( Form.Handle, FALSE );
EnableMenuItem( hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED );
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations } end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
canclose:=false;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
self.OnCloseQuery:=nil;
close;
end;end.
//给分吧:)
self.onclosequery:=FormCloseQuery;
AClose : Boolean;FormCreate时
AClose := False;关闭窗口的button Click时
AClose := True;在Form的OnCloseQuery中检测
AClose的值procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
canclose := False;
if AClose then
begin
canclose := True;
end;
end;
这样做虽然笨一点,但也能达到需要的效果。
Shift: TShiftState);
begin
if (ssAlt in shift) and (Key=VK_F4) then
begin
B:=False;
FormCloseQuery(sender,B);
end;
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if B=False then
CanClose:=False
else
CanClose:=True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
B:=True;
Close;
end;