这是完美的代码,不论是主窗体,还是子窗体,都适用。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WMSysCommand(var Msg: TWMSysCommand)
message WM_SYSCOMMAND;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
{ TForm1 }
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
{ 如果想在按下最小化按钮后,只做你想做的事情,而不想让窗口最小化 }
if Msg.CmdType = SC_MINIMIZE then
ShowMessage('wo shi xiaobenben');
else
inherited;
{ 如果想在按下最小化按钮后,先做你想做的事情,再让窗口最小化 }
if Msg.CmdType = SC_MINIMIZE then
ShowMessage('wo shi xiaobenben');
inherited;
{ 如果想在按下最小化按钮后,先让窗口最小化,再做你想做的事情 }
inherited;
if Msg.CmdType = SC_MINIMIZE then
ShowMessage('wo shi xiaobenben');
end;
end.