Question

If you hide the main form (Form1) and show another (Form2), you are left without an application icon in the taskbar. Is there a way to correct this so I have application icon for the child forms too ?

Was it helpful?

Solution

In the following, when I refer to owner, I mean the Windows concept rather than the VCL concept.

As I understand it, you are asking how to get your other form to have a button on the taskbar. The way to arrange for a top-level window to have a button on the taskbar is to:

  1. Make the window visible, and unowned, or
  2. Make the window visible, and have the WS_EX_APPWINDOW extended window style.

The main form of your application, Form1, is unowned. When it is visible, it has a button on the taskbar.

The other forms in your application have owners. Hence they do not have buttons on the taskbar.

In order to make your other forms have buttons on the taskbar you need to ensure that either of the options above applies. This involves overriding CreateParams.

type
  TForm2 = class(TForm)
  ....
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  ....
  end;
....
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := 0;
end;

The above gives you option 1. For option 2 you would write it like this:

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;

You ask in the comments where to place this code. Well, VCL forms are implemented on top of Win32. And that means that VCL forms are implemented as top-level windows. Windows are created by calls to CreateWindowEx which receives various parameters. Windows are, potentially, re-created during the lifetime of a form, which requires some scaffolding.

Part of that scaffolding is a mechanism for windows VCL controls to supply the parameters to be passed to CreateWindowEx. Those parameters are supplied in the protected virtual method CreateParams. You never call that method, you may optionally implement it. The framework calls it when it needs to know the parameters required for CreateWindowEx.

Usually VCL properties map to parameters (e.g. window style) passed to CreateWindowEx. However, for both of the options I describe above there are no such VCL properties. So you need to implement CreateParams.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top