Board index » delphi » Always On Top / fsStayOnTop

Always On Top / fsStayOnTop

Delphi 4 & 6, Windows 2000 & XP

Problem:

If the main form of an application has the FormStyle set as
fsStayOnTop, this form is shown above other applications.

However, if another of the project's form has the fsStayOnTop property
set, the form is only shown on top of other forms within the same
application (not above other application's windows).

I need to mimic the main form's behaviour, ie show it above other
application's forms, in other forms within a project.

The form will always be on top, so it is not necessary to have the
facility to change this option in the system menu.

I have come across this before, and I'm sure I solved it, but, rather
annoyingly, I can't remember how. I've searched quite extensively
through both Google and usenet, and I have not yet found a solution
that works.

If my memory serves me correctly, this problem only rears it's head in
Windows 2000 and XP, not Win98 etc.

Can anyone help?

 

Re:Always On Top / fsStayOnTop


On Tue, 01 Apr 2003 23:52:45 +1200, Gurble
<gurbleREM...@THISclear.net.nz> had this to say:

Quote
>Delphi 4 & 6, Windows 2000 & XP

>Problem:

>If the main form of an application has the FormStyle set as
>fsStayOnTop, this form is shown above other applications.

>However, if another of the project's form has the fsStayOnTop property
>set, the form is only shown on top of other forms within the same
>application (not above other application's windows).

Silly me. Within two minutes of posting the question, I've found the
answer ;-)

For anyone else interested:

----

DO Stay on TOP

Even though you can set FormStyle to fsStayOnTop, the form (not main)
remains on top of the desktop and of other forms in the project,
except any others that also have FormStyle set to fsStayOnTop. If one
fsStayOntop form launches another, neither form will consistently
remain on top.

To "stay on top" of all other windows on the desktop, you will have to
make the form parent the Desktop (together with fsStayOnTop). For the
application's main form, this is already the case, but not for any
other forms in your project. To achieve this for your secondary form
just override the CreateParams - by adding the WS_EX_TOPMOST to
ExStyle flag. Then the StayOnTop property will work as you expect (not
relative to all forms of your application but relative to all forms on
the desktop).

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do begin
    ExStyle := ExStyle or WS_EX_TOPMOST;
    WndParent := GetDesktopwindow;
  end;
end;

http://delphi.about.com/library/weekly/aa073101b.htm

Other Threads