Delphi MDI应用程序和MDI子项的标题栏

时间:2020-03-05 18:39:09  来源:igfitidea点击:

我有一个用Delphi 2006编写的MDI应用程序,该应用程序以默认主题运行XP。

有没有一种方法可以控制MDI Children的外观,从而避免每个窗口上都有大型XP样式的标题栏?

我试过将MDIChildren的BorderStyle设置为bsSizeToolWin,但是它们仍然呈现为普通形式。

解决方案

回答

我认为没有。以我的经验,Delphi中的MDI受到VCL中的实现(甚至可能由Windows API吗?)的严格限制和控制。例如,不要尝试隐藏MDI子项(如果尝试,将会得到一个异常,并且我们必须跳过几个API箍来解决该问题),或者更改MDI子项的主菜单与主机表单合并。

鉴于这些限制,也许我们应该重新考虑为什么首先要有特殊的标题栏?我猜这也是MDI标准化的很好理由-用户可能会喜欢它:)

(PS:很高兴在这里看到一个Delphi问题!)

回答

谢谢onnodb

不幸的是,客户坚持使用MDI和较小的标题栏。

我已经设计出一种实现方法,即通过覆盖Windows CreateParams隐藏标题栏,然后创建自己的标题栏(带有一些用于移动鼠标的简单面板)。效果很好,所以我想我可以由客户端运行它,看看它是否可以...

回答

MDI的工作方式与我们要尝试做的事情并不一致。

如果需要" MDI"格式,则应考虑使用内置或者商业对接软件包,并使用对接设置来模仿MDI感觉。

在我的Delphi应用程序中,我经常使用TFrames并将它们作为主窗体的父级,并最大化它们,以便它们占用客户区。这为我们提供了类似于Outlook外观的内容。它有点像这样:

TMyForm = class(TForm)
private
  FCurrentModule : TFrame;
public
  property CurrentModule : TFrame read FModule write SetCurrentModule;
end;

procedure TMyForm.SetCurrentModule(ACurrentModule : TFrame);
begin
  if assigned(FCurrentModule) then
    FreeAndNil(FCurrentModule);  // You could cache this if you wanted
  FCurrentModule := ACurrentModule;
  if assigned(FCurrentModule) then
  begin
    FCurrentModule.Parent := Self;
    FCurrentModule.Align := alClient;
  end;
end;

要使用它,我们只需执行以下操作:

MyForm.CurrentModule := TSomeFrame.Create(nil);

有一个很好的论据,即我们应该使用所使用的接口(创建IModule接口或者其他东西)。我经常这样做,但是它比在这里解释概念要复杂。

高温超导

回答

我们需要的所有重载过程CreateWindowHandle都是这样的:

unit CHILDWIN;
interface
uses Windows, Classes, Graphics, Forms, Controls, StdCtrls;

type
  TMDIChild = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure CreateWindowHandle(const Params: TCreateParams); override;
  end;

implementation

{$R *.dfm}
procedure TMDIChild.CreateWindowHandle(const Params: TCreateParams);
begin
  inherited CreateWindowHandle(Params);
  SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;
end.