Form is hidden behind other forms when ShowModal is called

后端 未结 6 1253
攒了一身酷
攒了一身酷 2020-12-04 22:34

My application is based on modal forms. Main form opens one form with ShowModal, this form opens another with ShowModal, so we have stacked modal forms. There is sometimes a

6条回答
  •  不知归路
    2020-12-04 22:57

    Sorry for adding a separate answer, but I have done a bit more research, and some of it indicates that my previous answer (DisableProcessWindowsGhosting) doesn't help. Since I can't always reproduce this issue, I cannot say for sure.

    I found a solution that appears to appropriate. I referenced the code in Delphi 2007 for the CreateParams method and it matches pretty close (without having all of the other code that handles PopupMode).

    I created the unit below which subclasses TForm.

    unit uModalForms;
    
    interface
    
    uses Forms, Controls, Windows;
    type
      TModalForm = class(TForm)
      protected
        procedure CreateParams(var params: TCreateParams); override;
      end;
    
    implementation
    
    procedure TModalForm.CreateParams(var params: TCreateParams);
    begin
      inherited;
    
      params.WndParent := Screen.ActiveForm.Handle;
    
      if (params.WndParent <> 0) and (IsIconic(params.WndParent)
        or not IsWindowVisible(params.WndParent)
        or not IsWindowEnabled(params.WndParent)) then
        params.WndParent := 0;
    
      if params.WndParent = 0 then
        params.WndParent := Application.Handle;
    end;
    

    What I do then is include this unit in with a form unit, and then change the form's class (in the .pas code file) from class(TForm) to class(TModalForm)

    It works for me, appears to be close to CodeGear's solution.

提交回复
热议问题