Vlad
Vlad

Reputation: 1433

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

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?

Upvotes: 5

Views: 842

Answers (1)

David Heffernan
David Heffernan

Reputation: 613511

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.

Upvotes: 5

Related Questions