How to make my Forms always to be on top my main form?
Asked Answered
R

1

5

How to make my non-modal forms to always be on top of my main form?

I have tried:

procedure TForm3.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := Application.MainForm.Handle;
end;

Which seems to work fine. Is that correct way?

Recycle answered 13/12, 2013 at 18:44 Comment(1)
Yes, that will work, since Delphi 7 does not have the TForm.PopupParent property that was introduced in Delphi 2007 to address this issue.Swiger
V
5

This is the Win32 concept of window ownership. An owned window always appears on top of its owner. The owner is specified in the call to CreateWindow and can then not be modified.

In the VCL you specify the owner by setting WndParent in CreateParams, and the framework then passes that on to CreateWindow. The VCL does this for you but in older versions the owner handling is, well, somewhat flaky. Modern versions are better and allow more control through the PopupMode and PopupParent properties.

Your code will therefore have the effect that you desire.

Violative answered 13/12, 2013 at 18:59 Comment(2)
Thanks. However I have a strage (?) behaviour, when I minimized the Main form, all other form remain visible on the desktop, and do not "hide". Is there something could be done about this?Recycle
Do the same as I suggest in my answer to your other question, but handle WM_SYSCOMMAND in the main form and hide all the other windows. You should probably remember their state so that you can restore them when the window is restored. I did my testing on D6 which I think is very similar to D7. But it really does suck at this. Modern Delphi is much better.Violative

© 2022 - 2024 — McMap. All rights reserved.