方法一:截获WM_SYSCOMMAND消息,看窗体是否处于最小化
type
TForm1 = class(TForm)
private
procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
//...
end;
implementation
{$R *.DFM}
procedure TForm1.WMSysCommand(var Message:TMessage);
begin
if Msg.WParam = SC_MINIMIZE then
begin
// 你要执行的代码
Form1.WindowState := wsMinimized;
end
else
inherited;
end;
方法二:判断是否点击了窗体上的最小化按钮
type
TForm1 = class(TForm)
private
procedure Minimize(var BtnDown: TWMNCLBUTTONDOWN); message WM_NCLBUTTONDOWN;
//...
end;
implementation
{$R *.DFM}
procedure TForm1.Minimize(var BtnDown: TWMNCLBUTTONDOWN);
begin
if BtnDown.HitTest = HTMINBUTTON then
begin
// 你要执行的代码
Form1.WindowState := wsMinimized;
end
else
inherited;
end;