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

标签 delphi mdi multiple-monitors sdi

我想创建一个带有自己的任务栏的 MDI 应用程序,以便用户可以快速访问他/她想要显示在前面的子窗口。然后我想到,使用两个或更多显示器的用户可以将子窗口从应用程序的主窗体内部拖动到应用程序的外部,例如另一个显示器。

如何做到这一点?

最佳答案

也许这个示例 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.

关于delphi - 如何从主窗体中拉出MDI子窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16551117/

相关文章:

delphi - 预构建事件在 Windows 7 中有效,在 XP 中失败

string - 删除备忘录上的特定行

.net - 在 .NET 中创建新的最大化 MDI 子窗体的图标问题

swift - 查找哪个监视器或屏幕包含鼠标指针 - swift、macos

delphi - 将接口(interface)的方法作为参数传递

delphi - 空的 Try/Finally block 有什么用途吗?

VB.NET 循环通过特定的 MDI 子项

c# - 指定为此表单的 MdiParent 的表单不是 MdiContainer

c# - 防止 ToolStripMenuItems 跳转到第二个屏幕

c# - 双屏编程问题