Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1794
  • Last Modified:

fsStayOnTop form staying on top of all apps - I only want on top of *my* app

Hi,

  If I create a form that has a form style of fsStayOnTop from a MDIChild, the StayOnTop form will only stay on top of my app...so if I ALT+Tab to another app, the stayOnTopForm is under the app I switch to.

  BUT....if I create the fsStayOnTop form from a form that is modal, the StayOnTop form stays on top of ALL apps...so if I ALT+Tab to another app, my stay on top form is still on top, with the other app underneath it, and finally the rest of my app on teh bottom.

  Does anyone know how to get the behavior in the first scenario when creating the stayOnTop form from a modal window?

Thanks,

-John
0
jdorlon
Asked:
jdorlon
1 Solution
 
AVAHLDICKCommented:
John,

MDIChild means that this window belong from an "parent" Window, and this child window affects just into the main window and his brothers.

What does exactly you want deploy ? There can are other solutions...

Adilson
0
 
ziolkoCommented:
use: SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
in Application.OnActivate and after Form.Show and SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); in Application.OnDeactivate.
ziolko.



0
 
jdorlonAuthor Commented:
Thank you for your replies.

Ziolko, I tried it what you suggested but it behaves the same.  I set a breakpoint in teh application.OnDeactivate and I can see that it does execute.

Avahldick, here is what I want to do:  I am creating a stayOnTop window from a window that is being shown with a "showModal" command.  When I ALT+Tab to another app, my stayOnTop window is on top of the other app.  I only want it to be on top of the app which owns it.

Thanks your your help!

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ziolkoCommented:
jdorlon > maybe what I posted before is not complete, I've solved this problem but code is in my office, I'll post comment tomorrow in the morning.
ziolko.
0
 
MaximilianopCommented:
Well, the thing is: if you set FormStyle to fsStayOnTop, then it will stay on top, no matter what.

A solution to do is is instead of using StayOnTop, is to creeate a timer, and in it's OntimerEvent, write the next:
IF "Form that must be on top" doesn't has focus, and non of it's child have it either, then Form.setfocus;
Example:
Form called Form1;
Mainform child called Edit1;
Timer called Timer1;

TForm1.Timer1OnTimer(Sender: TObject);
begin
  If (not Form1.focused) and (not Edit1.focused) Then form1.setfocus;
end;

By setting the focus to the Form, it brings it to top.
Obvisuly, you can change the conditions under wich the form1.setfocus is not executed.
0
 
ziolkoCommented:
Add TApplicationEvents to form that should stay on top, in design mode set FormStyle to fsNormal (not fsStayOnTop !!)
then

Form's OnActivate evet handler:
procedure TWinInfo.FormActivate(Sender: TObject);
begin
 SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
end;

ApplicationEvents' OnActivate event handler:
procedure TWinInfo.ApplicationEventsActivate(Sender: TObject);
begin
 if Visible then
   SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
end;


ApplicationEvents' OnDeActivate event handler:
procedure TWinInfo.ApplicationEventsDeactivate(Sender: TObject);
begin
 if Visible then
   SetWindowPos(Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
end;

ziolko.
0
 
jdorlonAuthor Commented:
Thank you Ziolko, that worked perfectly!  (although I forgot to change the formstyle to fsNormal in design mode and it worked anyway)

Maxmilianop - a fsStayOnTop is always on top of the app, but it is not always on top of other apps!  Without the code that Ziolko provided, a fsStayOnTop will act diffently depending on the modality of the from from which it was created.

Ok, case closed!  Thanks again!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now