Board index » delphi » How to get a form always on top.

How to get a form always on top.

I want to make a form that is always on top in the entire windows
environment (i.e. on top of word, excel etc). Setting FormStyle =
fsStayOnTop does not do the job; if I start Word or Excel, it displays over
my "StayOnTop-Form".

Any solutions?

Stan Megens

smeg...@inter.nl.net

 

Re:How to get a form always on top.


Word and Excel interfering with stay on top is a new one on me... You can
try this in your form to set the "OnTop" on or off.  Create a variable
called OnTop, to hold whether the form is on top or not, and do this to set
the window state:

if OnTop then Order := HWND_TOPMOST
              else Order := HWND_NOTOPMOST;

SetWindowPos( Handle, Order, Left, Top, Width, Height,
                         SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOSIZE);

(Order is type HWND).
--
Regards,

Matt Palmer
Author of mpDockManager
http://freespace.{*word*269}.net/matt.palmer/

Quote
Stan Megens <smeg...@inter.nl.net> wrote in message

news:873qtg$1dj15@bornews.borland.com...
Quote

Re:How to get a form always on top.


Thanks, but....

This still doesn't work.
When I show the form, I can always make it disappear behind another window,
be it Word, Excel, the Delphi IDE or even the Calculator. I would like my
form to stay on top of all windows in the environment. (But I don't know if
it is possible...). Or is there something else I should do or try. Showing
the form Modal or Not doesn't make a difference either.

Stan.

Matt P <matt.pal...@{*word*269}.net> schreef in berichtnieuws
873v1p$1...@bornews.borland.com...

Quote
> Word and Excel interfering with stay on top is a new one on me... You can
> try this in your form to set the "OnTop" on or off.  Create a variable
> called OnTop, to hold whether the form is on top or not, and do this to
set
> the window state:

> if OnTop then Order := HWND_TOPMOST
>               else Order := HWND_NOTOPMOST;

> SetWindowPos( Handle, Order, Left, Top, Width, Height,
>                          SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOSIZE);

> (Order is type HWND).
> --
> Regards,

> Matt Palmer
> Author of mpDockManager
> http://freespace.{*word*269}.net/matt.palmer/
> Stan Megens <smeg...@inter.nl.net> wrote in message
> news:873qtg$1dj15@bornews.borland.com...

Re:How to get a form always on top.


Errmm.. SetWindowPos works for me, on Win95, Win98 and NT4... What exactly
are you doing.  The devil's in the details, as they say.

You say that you're "showing" the form - do you mean it's created but
invisible, and then you show it? Are you setting the OnTop property AFTER
you show the form?  If you dock/undock forms, this also has the effect of
recreating the window, changing the handle and incidentally resetting the on
top property...

More info needed!

--
Regards,

Matt Palmer
Author of mpDockManager
http://freespace.{*word*269}.net/matt.palmer/

Quote
Stan Megens <smeg...@inter.nl.net> wrote in message

news:8742pr$1kq11@bornews.borland.com...
Quote
> Thanks, but....

> This still doesn't work.
> When I show the form, I can always make it disappear behind another
window,
> be it Word, Excel, the Delphi IDE or even the Calculator. I would like my
> form to stay on top of all windows in the environment. (But I don't know
if
> it is possible...). Or is there something else I should do or try. Showing
> the form Modal or Not doesn't make a difference either.

> Stan.

> Matt P <matt.pal...@{*word*269}.net> schreef in berichtnieuws
> 873v1p$1...@bornews.borland.com...
> > Word and Excel interfering with stay on top is a new one on me... You
can
> > try this in your form to set the "OnTop" on or off.  Create a variable
> > called OnTop, to hold whether the form is on top or not, and do this to
> set
> > the window state:

> > if OnTop then Order := HWND_TOPMOST
> >               else Order := HWND_NOTOPMOST;

> > SetWindowPos( Handle, Order, Left, Top, Width, Height,
> >                          SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOSIZE);

> > (Order is type HWND).
> > --
> > Regards,

> > Matt Palmer
> > Author of mpDockManager
> > http://freespace.{*word*269}.net/matt.palmer/
> > Stan Megens <smeg...@inter.nl.net> wrote in message
> > news:873qtg$1dj15@bornews.borland.com...

Re:How to get a form always on top.


One way is to override the CreateParams procedure in your form.

ie:

procedure TForm1.CreateParams( var Params: TCreateParams );
begin
  inherited;
  Params.exStyle:=Params.exStyle or ws_ex_topmost;
end;

Quote
"Stan Megens" <smeg...@inter.nl.net> wrote in message

news:873qtg$1dj15@bornews.borland.com...
Quote
> I want to make a form that is always on top in the entire windows
> environment (i.e. on top of word, excel etc). Setting FormStyle =
> fsStayOnTop does not do the job; if I start Word or Excel, it displays
over
> my "StayOnTop-Form".

> Any solutions?

> Stan Megens

> smeg...@inter.nl.net

Re:How to get a form always on top.


On Mon, 31 Jan 2000 12:22:48 +0100, "Stan Megens"

Quote
<smeg...@inter.nl.net> wrote:

Hi Stan,

we talked about the StayOnTop problem last evening, so I created a new
app , put the FormStyle to fsStayOnTop and compiled it. Excel couldn't
beat me to the punch, as I stayed on top (same goes for other
applications I was running).
So I have a few questions for you:
 - Which version of Office are you using? (it could be (highly
unlikely) that different versions yield different results. Mine is
Office 97);
 - Are you sure you're not resetting the FormStyle in code?
 - Are you doing other stuff which could influence the Z-order of
stacked windows?

b.t.w.: If you want, we can communicate in private mail.

Success,

Frank.

Quote
>I want to make a form that is always on top in the entire windows
>environment (i.e. on top of word, excel etc). Setting FormStyle =
>fsStayOnTop does not do the job; if I start Word or Excel, it displays over
>my "StayOnTop-Form".

>Any solutions?

>Stan Megens

>smeg...@inter.nl.net

Re:How to get a form always on top.


I started testing with a new application (form1) and of course the "stay on
top" worked fine.

Then I added a simple button which calls form2 (also stay on top):
        Form1.Hide;        // Removing this line still doesn't help
        Form2.Show;

If I run it, it works fine, until I press the button which shows Form2.
This is what I'm trying to do in my original application. Does this help to
find a solution, or should I rework my forms?

Stan Megens

Re:How to get a form always on top.


If it will work for your purposes, use the ShowModal command.

    Form2.ShowModal;

Hope this helps,
TS

Quote
"Stan Megens" <smeg...@inter.nl.net> wrote in message

news:881r64$eb325@bornews.borland.com...
Quote
> I started testing with a new application (form1) and of course the "stay
on
> top" worked fine.

> Then I added a simple button which calls form2 (also stay on top):
>         Form1.Hide;        // Removing this line still doesn't help
>         Form2.Show;

> If I run it, it works fine, until I press the button which shows Form2.
> This is what I'm trying to do in my original application. Does this help
to
> find a solution, or should I rework my forms?

> Stan Megens

Other Threads