5

我目前正在为现有的 Delphi 应用程序编写一个窗口系统。

目前,该程序由许多完整尺寸的表格组成,这些表格按照需要的顺序模态显示,用户不能移动任何一个。我的目标是让所有这些形式都可以移动。以前表单是堆叠在一起的,但是由于没有一个可以移动,因此用户看不到背景表单。到目前为止,我的解决方案是在打开一个新孩子时隐藏“父”表单,并在该孩子关闭时重新显示它。

不幸的是,由于每个孩子都是用 showModal 调用的,所以直到模态过程完成之后才调用使父表单可见,因此在子表单被隐藏之后,用户会看到一瞬间没有任何表单可见的闪烁。

有没有办法可以防止模态表单在其过程完成后自动隐藏?一旦父表单再次可见,这将允许我手动隐藏它们。我试图在每个子窗体的 FormHide 事件中安排这个,但这不起作用,因为在打开它自己的一个子窗体时,子窗体也被隐藏。

编辑:

这是我到目前为止根据雷米的建议所得到的

procedure openModalChild(child: TForm; parent: TForm);
var
  WindowList: Pointer;
  SaveFocusCount: Integer;
  SaveCursor: TCursor;
  SaveCount: Integer;
  ActiveWindow: HWnd;
  Result: integer;
begin
  CancelDrag;
  with child do begin
  Application.ModalStarted;
  try
  ActiveWindow := GetActiveWindow;
  WindowList := DisableTaskWindows(0);
  //set the window to fullscreen if required
  setScreenMode(child);
  try
    Show; //show the child form
    try
      SendMessage(Handle, CM_ACTIVATE, 0, 0);
      ModalResult := 0;
      repeat
        Application.HandleMessage;
        //if Forms.Application.FTerminate then ModalResult := mrCancel else
          if ModalResult <> 0 then closeModal(child as TCustomForm);
      until ModalResult <> 0;
      Result := ModalResult;
      SendMessage(Handle, CM_DEACTIVATE, 0, 0);
      if GetActiveWindow <> Handle then ActiveWindow := 0;
    finally
      parent.Show;
      Hide;
    end;
  finally
    EnableTaskWindows(WindowList);
    parent.Show; //reshow the parent form
    if ActiveWindow <> 0 then SetActiveWindow(ActiveWindow);
  end;
  finally
    Application.ModalFinished;
  end;
  end;
end;

这很好用,但唯一的问题是活动的重复循环永远不会中断,即使在孩子被转义之后,父表单也永远不会重新显示。有什么办法可以解决这个问题吗?

4

1 回答 1

10

ShowModal()Show()在进入其模态处理循环之前显式调用,并Hide()在退出循环后立即显式调用。如果不更改 VCL 的 Forms.pas 源文件中的代码,就无法更改它。

如果您需要更好地控制窗口,而无需编辑 VCL 源代码,则根本不要使用ShowModal()。根据需要使用Show()Hide()DisableTaskWindows()EnableTaskWindows()您自己。我建议您查看 Forms.pas 以了解它们的使用方式。将实现复制ShowModal()到您自己的函数中,然后您可以根据需要对其进行自定义。

于 2011-12-16T21:51:55.587 回答