procedure TFrmMain.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); var show: boolean; begin //当前子窗体的状态为最大化时,显示三个按纽 show := (self.ActiveMDIChild <> nil) and (self.ActiveMDIChild.WindowState = wsMaximized); if assigned(BtnClose) and BtnClose.Visible <> Show then BtnClose.Visible := Show; if assigned(BtnMin) and BtnMin.Visible <> Show then BtnMin.Visible := Show; if assigned(BtnRestore) and BtnRestore.Visible <> Show then BtnRestore.Visible := Show; end;
//设置按纽的相对位置不变
procedure TfrmMain.SetMDIFormActionPos; begin if assigned(BtnClose) then begin BtnClose.left := Width - 26; BtnClose.top := 6; end; if assigned(BtnRestore) then begin BtnRestore.Left := Width - 44; BtnRestore.Top := 6; end; if assigned(BtnMin) then begin BtnMin.Left := Width - 60; BtnMin.Top := 6; end; end;
procedure TFrmMain.FormResize(Sender: TObject); begin SetMDIFormActionPos; end;
procedure TFrmMain.FormDestroy(Sender: TObject); begin //释放资源 if assigned(BtnClose) then begin WindowClose.ActionList := nil; WindowClose.free; BtnClose.Free; BtnClose := nil; end; if assigned(BtnRestore) then begin WindowRestore.ActionList := nil; WindowRestore.free; BtnRestore.Free; BtnRestore := nil; end; if assigned(BtnMin) then begin WindowMinimize.ActionList := nil; WindowMinimize.free; BtnMin.Free; BtnMin := nil; end; end;
{ TWindowRestore }
procedure TWindowRestore.ExecuteTarget(Target: TObject); begin inherited; with GetForm(Target) do ActiveMDIChild.WindowState := wsnormal; end;
{ TMDIButton }
procedure TMDIButton.wndproc(var message: Tmessage); begin if message.msg = wm_SetFocus then exit; inherited wndproc(message); end;
{ TWindowMinimize }
procedure TWindowMinimize.ExecuteTarget(Target: TObject); begin inherited; with GetForm(Target) do ActiveMDIChild.WindowState := wsMinimized; end;
procedure TFrmMain.open1Click(Sender: TObject); begin with Tform.create(self) do begin formstyle := fsMDIChild; end; end;