【问题标题】:Multiple forms with Firemonkey showing multiple items in windows menuFiremonkey 的多个表单在 Windows 菜单中显示多个项目
【发布时间】:2011-12-13 12:29:23
【问题描述】:

我目前正在尝试使用 Firemonkey 并遇到了这个问题。 当我的应用程序中有多个表单时,我得到相同数量的项目 在我的一个应用程序的 Windows 菜单栏中(见屏幕截图)。

在常规的 VCL 应用程序中,只有一项标识应用程序 (所以我的屏幕截图只包含“Form2”项)。

有人知道我怎样才能完成与 VCL 应用程序相同的行为吗? 所以我的多表单申请只有一个项目???

提前致谢!

提斯

编辑:我设法显示了第二个表单,底部菜单只有一项,但表单的“透明度”属性必须为真!所以为了让第二个表单可见,需要在第二个表单中放置一个TRectangle(没有可见的带有标题和按钮的框架)...

【问题讨论】:

  • 在 Vista 中也会发生......至少在 fmx 中......

标签: forms delphi firemonkey


【解决方案1】:

我找到了解决方法。

当您创建具有所有者的表单时,FireMonkey 应该将所有者传递给 Windows CreateWindowEx 函数,但它不会。

在单元FMX.Platform.Win中,在CreateWindow()函数中,改变这个:

  Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
    Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
    GetDesktopWindow, 0, hInstance, nil);

到这里:

  // If there's an owner, and it's a form, then create the window as a child
  if (AForm <> nil) and (AForm.Owner <> nil) and (AForm.Owner is TForm) then
  begin
    // Child window
    Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
      Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
      HandleToHWND(TForm(AForm.Owner).Handle), 0, hInstance, nil);
  end
  else
  begin
    // Desktop window
    Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
      Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
      GetDesktopWindow, 0, hInstance, nil);
  end;

因此,如果您要创建子表单,尤其是模态表单,请确保在创建父表单时将其指定为所有者:

MyModalForm := TMyModalForm.Create(MyParentForm);
MyModalForm.ShowModal;

然后,修复后一切都会按预期工作。

不要忘记从项目设置中的自动创建表单列表中删除子表单。

【讨论】:

  • 我在编辑“FMX.Platform.Win”文件时遇到困难,无法正确保存。将进一步尝试,但我希望找到解决方案而无需更改 FMX 文件。
  • 如果我将它作为一个新文件添加到我的项目中并应用更改,它就可以工作。我希望在不必更改源 FMX 文件的情况下找到解决方案,因为我也在尝试使用 MonkeyMixer (simonjstuart.com/2011/10/19/…) 将其添加到我的 VCL 项目中。
猜你喜欢
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
  • 2019-10-22
  • 1970-01-01
相关资源
最近更新 更多