views:

554

answers:

2

In Delphi (2009 Pro) - I have a main form that can create non-modal child windows. I want whichever form has the focus to draw on top - even if it is the main window that has the focus.

A: 

Multiple windows cannot have the focus at the same time. I assume you meant to say that you want your non-modal child Form to be on top when only the MainForm has focus. Have you tried setting the child Form's FormStyle property to fsStayOnTop yet?

Remy Lebeau - TeamB
Doesn't he want the exact opposite? The Main Form should be able to become on top of other windows what Delphi 2007 and 2009 changed.
Andreas Hausladen
+6  A: 

With Delphi 2007/2009 the VCL changed its behavior regarding the parent of a form. In Delphi 1-2006 the parent of a form was the hidden application window (Application.Handle). In Delphi 2007/2009 the parent of a form is the main form and the main form's parent is the desktop.

If you want to change this you can either change the *.dpr line Application.MainFormOnTaskbar to False what gives you the the old behavior back but also makes your application look strange in Vista and Windows 7. Or you can override the virtual CreateParams method in all your non-modal child forms and set the Params.WndParent field to the desktop (HWND_DESKTOP) or the still existing Application.Handle.

type
  TMyChildForm = class(TForm)
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  end;

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := Application.Handle;
end;
Andreas Hausladen