如何从主窗体中拉出MDI子窗口?

时间:2013-05-14 19:18:12

标签: delphi mdi multiple-monitors sdi

我想用它自己的任务栏创建一个MDI应用程序,这样用户就可以快速访问他/她想要带到的子窗口。然后我认为使用两个或更多监视器的用户可以将子窗口从我的应用程序的主窗体内部拖到其外部,例如另一个监视器。

怎么做?

1 个答案:

答案 0 :(得分:4)

也许这个示例MDI客户端表单代码提供灵感:

unit Unit3;

interface

uses
  Windows, Messages, Controls, Forms;

type
  TForm3 = class(TForm)
  private
    FSizing: Boolean;
    procedure WMNCMouseLeave(var Message: TMessage);
      message WM_NCMOUSELEAVE;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged);
      message WM_WINDOWPOSCHANGED;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Resize; override;
  end;

implementation

{$R *.dfm}

{ TForm3 }

var
  FDragging: Boolean = False;

procedure TForm3.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  if FormStyle = fsNormal then
    Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW
  else
    Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
end;

procedure TForm3.Resize;
begin
  inherited Resize;
  FSizing := True;
end;

procedure TForm3.WMNCMouseLeave(var Message: TMessage);
begin
  inherited;
  FDragging := False;
end;

procedure TForm3.WMWindowPosChanged(var Message: TWMWindowPosChanged);
var
  P: TPoint;
  F: TCustomForm;
  R: TRect;
begin
  inherited;
  if not FDragging and not FSizing and not (fsShowing in FormState) and
    (WindowState = wsNormal) then
  begin
    F := Application.MainForm;
    P := F.ScreenToClient(Mouse.CursorPos);
    R := F.ClientRect;
    InflateRect(R, -5, -5);
    if not PtInRect(R, P) and (FormStyle = fsMDIChild) then
    begin
      FDragging := True;
      FormStyle := fsNormal;
      Top := Top + F.Top;
      Left := Left + F.Left;
    end
    else if PtInRect(R, P) and (FormStyle = fsNormal) then
    begin
      FDragging := True;
      FormStyle := fsMDIChild;
    end;
  end;
  FSizing := False;
end;

end.