Minimize modal form with ExStyle=WS_EX_APPWINDOW


The program have main form and a N-number of other forms that are created as modal from main form.
Workers are using 2 or 3 monitors(screens) simultaneously, so they doesnt want to see deactivated main form if modal form is placed on another screen.
I added ExStyle=WS_EX_APPWINDOW to all modal forms and hide main form when new modal is created

ActiveModalForm:=TComponentClass(AClass).Create(Application) as TCustomForm;
Hide(); //hides main form

ActiveModalForm.ShowModal; //show new modal window

FreeAndNil(ActiveModalForm); // destroy modal window
Show(); //shows main form
Modal form CreateParams:
procedure TfrmNewModal.CreateParams(var Params: TCreateParams); 
begin
  inherited CreateParams(Params);
  with Params do
  begin
    WndParent := 0;
    ExStyle := ExStyle OR WS_EX_APPWINDOW;
  end;
end;
The problem is that if user want to minimize that modal form it will minimize and show again.
I'm trying to minimize it by this way:
procedure TfrmNewModal.WMSysCommand(var Msg: TWMSysCommand);
begin
  case (msg.cmdtype and $FFF0) of
    SC_MINIMIZE:
    ShowWindow( handle, SW_MINIMIZE );
    SC_RESTORE:
    ShowWindow( handle, SW_RESTORE )
  else
    inherited;
  end;
end;
I think that the problem is in WS_EX_APPWINDOW, but i cant imagine at the current moment another way how i can show modal window on task bar and minimize it.
Can anybody help?
Thank You.
  • 1
    I don't think that you should be using a modal form. Hide the main form and show the other form modeless. Better to set WndParent to 0 to make it show in taskbar. Adding WS_EX_APPWINDOW pointless once you have made the window unowned. – David Heffernan Jul 7 '16 at 6:20 
  • @David Heffernan, i tried to write ActiveModalForm.Show; but no effect. When i'm trying to minimize it the form is minimising and restoring at the same moment (blinks) – Kast2K Jul 7 '16 at 6:26
  • 1
    Why do you want a modal form? Hide the main form. Show the other form. Set WndParent to 0 for the other form. That's it. Remove everything else. Everything else. Start from scratch and make a minimal reproducible example. Experiment with that. – David Heffernan Jul 7 '16 at 6:28
  • @David Heffernan , thank You very much! I created a test project and added functions step by step. I found error in ForceForegroundWindow. Now Everything works OK. Thank You! – Kast2K Jul 7 '16 at 6:52 
0
Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        Dim _CreateParams As CreateParams = MyBase.CreateParams
        ' WS_EX_COMPOSITED
        ' WS_EX_LAYERED
        _CreateParams.ExStyle = _CreateParams.ExStyle Or &H2000000
        _CreateParams.ExStyle = _CreateParams.ExStyle Or &H80000
        Return _CreateParams
    End Get
End Property
 New contributor

Post a Comment

0 Comments