Windows – How to get taskbar buttons for forms that aren’t the main form

delphiformswindows

How do you make a form appear on the taskbar in Delphi? In Firefox, for example, when you open a page in a new window, it creates another window on the taskbar without creating a new process. At the moment my Delphi application opens a new form when a button is clicked, but there is still only one thing on the task bar, so you can't alt-tab between the main form and the form that is created when the button is clicked. How do I change it so that the new form appears with a new taskbar button? My current code looks like this:

procedure Form1ButtonClick(Sender: TObject);
begin
    Form2.Show;
end;

I have been messing around with CreateWindowEx, but ideally I would like to find a simpler solution than directly using the Windows API.

Best Answer

If I understand what you want correctly, you can show your secondary forms on the task bar by overriding it's CreateParams procedure, as explained in Minimize child forms independent of the main form delphi.about.com article, like this:

interface

type
  TMyForm = class(TForm)
  ...
  protected
    procedure CreateParams(var Params: TCreateParams) ; override;
  ...

implementation

procedure TMyForm.CreateParams(var Params: TCreateParams) ;
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
  Params.WndParent := 0;
end;
Related Topic