Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Minimize main form without sub form

GrifitzGrifitz Member Posts: 9
I have form1 as main form and form2 as sub form
Whenever I minimized form1, form2 will minimized too and also the other forms in the application.
How to minimized the main form but without the other forms become minimized too ??

Comments

  • injektiloinjektilo Member Posts: 113
    the first created form while be the main form, and yes, whenever it is minimized all forms will minimize. to get around create a dummy main form but dont show it and treat the other forms as normal, ex:

    [code]
    program Project1;

    uses
    Forms,
    Unit1 in 'Unit1.pas' {Form1},
    Unit2 in 'Unit2.pas' {Form2},
    Unit3 in 'Unit3.pas' {Form3};

    {$R *.res}

    begin
    Application.Initialize;

    Application.CreateForm(TForm1, Form1); //dummy form
    Application.ShowMainForm := False;

    Application.CreateForm(TForm2, Form2);
    Form1.Show;

    Application.CreateForm(TForm3, Form3);
    Form2.Show;

    Application.Run;
    end.
    [/code]

    hope it helps

  • MasterijnMasterijn Member Posts: 188
    Hello, some additional stuff:
    The source of this behaviour is that all other forms are a 'child' form of the main form. SetParent(.Handle, 0) will make the form a child of the desktop, with it's own taskbar button, so it can also be minimized independend.



  • zibadianzibadian Member Posts: 6,349
    : Hello, some additional stuff:
    : The source of this behaviour is that all other forms are a 'child' form of the main form. SetParent(.Handle, 0) will make the form a child of the desktop, with it's own taskbar button, so it can also be minimized independend.
    :
    :
    :
    :
    You can also do that by setting the Parent property to nil.
  • MasterijnMasterijn Member Posts: 188
    : : Hello, some additional stuff:
    : : The source of this behaviour is that all other forms are a 'child' form of the main form. SetParent(.Handle, 0) will make the form a child of the desktop, with it's own taskbar button, so it can also be minimized independend.
    : :
    : :
    : :
    : :
    : You can also do that by setting the Parent property to nil.
    :
    not in the case of forms, those standard have their parent set to nil, the property TWinControl.ParentWindow can be set to 0, wich does the same call, but I think this is kinda new property.


  • zibadianzibadian Member Posts: 6,349
    : : : Hello, some additional stuff:
    : : : The source of this behaviour is that all other forms are a 'child' form of the main form. SetParent(.Handle, 0) will make the form a child of the desktop, with it's own taskbar button, so it can also be minimized independend.
    : : :
    : : :
    : : :
    : : :
    : : You can also do that by setting the Parent property to nil.
    : :
    : not in the case of forms, those standard have their parent set to nil, the property TWinControl.ParentWindow can be set to 0, wich does the same call, but I think this is kinda new property.
    :
    :
    :
    Then it was the Owner, which can be set only while creating the form. My error.
  • MasterijnMasterijn Member Posts: 188
    : : : : Hello, some additional stuff:
    : : : : The source of this behaviour is that all other forms are a 'child' form of the main form. SetParent(.Handle, 0) will make the form a child of the desktop, with it's own taskbar button, so it can also be minimized independend.
    : : : :
    : : : :
    : : : :
    : : : :
    : : : You can also do that by setting the Parent property to nil.
    : : :
    : : not in the case of forms, those standard have their parent set to nil, the property TWinControl.ParentWindow can be set to 0, wich does the same call, but I think this is kinda new property.
    : :
    : :
    : :
    : Then it was the Owner, which can be set only while creating the form. My error.
    :
    Thanks for your reaction, I'll explane it little more. It's about this overriden method, the blue section:
    [code]
    procedure TCustomForm.CreateParams(var Params: TCreateParams);
    var
    Icons: TBorderIcons;
    CreateStyle: TFormBorderStyle;
    begin
    inherited CreateParams(Params);
    InitAlphaBlending(Params);
    with Params do
    begin
    [blue]
    if (Parent = nil) and (ParentWindow = 0) then
    begin
    WndParent := Application.Handle;
    Style := Style and not (WS_CHILD or WS_GROUP or WS_TABSTOP);
    end;
    [/blue]
    WindowClass.style := CS_DBLCLKS;
    if (csDesigning in ComponentState) and (Parent = nil) then
    Style := Style or (WS_CAPTION or WS_THICKFRAME or WS_MINIMIZEBOX
    ...

    end;
    [/code]
    This makes that form-windows don't dock into their Parents:
    [code]Style := Style and not (WS_CHILD or WS_GROUP or WS_TABSTOP);[/code]
    This will set the main form as a parent:
    [code]WndParent := Application.Handle;[/code]
    Because of this sub-forms don't have taskbarbuttons and reac dependend on the main form (the minimizing). Windows doesn't know which form is the mainform, it's only difference is this: beeing the first form it recieves a Application.Handle of 0. Which means no-parent or the desktop-window.

    By setting TWinControl.ParentWindow:= 0; this can be undone.
    By setting Parent:= nil; (As default) The VCL code above, will keep or make this form a child-window of the main form. Forms are special in this way, because all (with a few exceptions) other TWinControls are standard child windows (WS_CHILD).
    The VCL-code above also shows that forms can act as child-windows! Indeed it's possible to put a form in a tabsheet, or a panel.


Sign In or Register to comment.