1
votes

I think this is a question that time after time appear here, but I looked over lots of questions, and didn't found the the right answer for me.

I have a parent form, with all "normal" attributes, and now I just created a child form, with "normal" attributes too. On my parent form, I have a ListView, when I click on some item at my ListView, I open the child form.

Now I need to keep this child form, on top of the main form, and when I minimize the child, the top gets minimized too, when I maximize the program, I see the child form only, until I close this form. So, the main form, with the ListView will be unavailable until I close the child form. If I select another item from my ListView, I open the child form again with the same behavior.

I don't know if this is hard to achieve, but I didn't found it over the google. Here is my simple demo code:

unit Unit1;

var
  Form1: TForm1;


implementation

uses Desktop;

procedure TForm1.RemoteDesktop1Click(Sender: TObject);
var
  DesktopForm: TForm2;
begin
  DesktopForm:= TForm2.Create(Self);
  DesktopForm.Show;
end;

And Desktop unit is just a VCL Form, without any code.

2
The real problem is that you are allowing a modal form to be minimizedDavid Heffernan

2 Answers

2
votes

Use showModal. To minimize MainWindow (all windows, minimize app actually), you should override WMSysCommand in child form:

procedure WMSyscommand(var Msg: TWmSysCommand); message WM_SYSCOMMAND;

.
.
.
procedure TForm2.WMSysCommand(var Msg: TWmSysCommand);
begin
  case (Msg.CmdType and $FFF0) of
    SC_MINIMIZE:  begin
                    Msg.Result := 0;
                    EnableWindow(Application.Handle, True);
                    Aplication.Minimize;
                  end;
    else inherited;
  end;
end;

Also Form event WindowStateChange could be used on non Windows.

I've run simple test without handling that event on LXDE Fedora23 (Lazarus) all forms have been minimize when modal.

1
votes

It sounds like you want a Modal form

DesktopForm.ShowModal;

instead of

DesktopForm.Show;

you will probably want to set

Application.ModalPopupModel to pmAuto also