Multiple windows in Delphi

by Apr 26, 2005

From a recent thread in borland.public.delphi.nativeapi.win32:

There's a problem in the way Delphi handles multiple open forms. Delphi applications can have multiple forms, and you will notice that each form does not appear on the task bar. Delphi forms do not have the WS_EX_APPWINDOW style set – this style is required if a window needs to appear in the task bar. But there is one icon, isn't there? That's the icon of the Delphi "Application" – and clicking on it in the task bar simply focusses the main window (or any other modal window above it)

If you need your "other" windows to appear in the task bar, then you can do this: Override the CreateParams procedure in your other forms, and write this code in there:

procedure CreateParams(var Params: TCreateParams); override;
procedure TForm1.CreateParams(var Params: TCreateParams);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;

Now, if you're doing this, you probably are writing applications where ndividual windows behave independently of the "main" form. You might notice that suddenly, the main form comes up in FRONT of the other top level form, like when showing hints or displaying dialog boxes from them. Reason: Delphi's Application variable is the culprit – it handles a lot of things including hint display, Dialog box messages etc. When it gets these messages, the main form gets activated, for some reason.

Fix: Don't just make your "other" forms with WS_EX_APPWINDOW. Make ALL your top level forms have that style, including your main form. (Use the same logic for the main form). Then, REMOVE the WS_EX_APPWINDOW style from the "Application" – using this code:

SetWindowLong(Application.Handle, GWL_EXSTYLE,

You'll have a lot less trouble then.