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
jdorlonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.