18

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.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467

2 Answers2

31

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;
dummzeuch
  • 10,975
  • 4
  • 51
  • 158
jachguate
  • 16,976
  • 3
  • 57
  • 98
  • 12
    The About.com article is wrong regarding how to set WndParent. The Old New Thing explains why [it's wrong to make the desktop be the parent of your application's windows](http://blogs.msdn.com/b/oldnewthing/archive/2004/02/24/79212.aspx). I've fixed the code here. – Rob Kennedy Mar 31 '11 at 00:06
  • 4
    You should do one or other, but no need for both in CreateParams. – David Heffernan Apr 28 '14 at 05:30
1

if not using of this line is better in form order :

Params.WndParent := 0;
MohsenB
  • 1,669
  • 18
  • 29