?
Solved

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

Posted on 2003-03-11
7
Medium Priority
?
1,514 Views
Last Modified: 2010-04-04
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
Comment
Question by:jdorlon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Expert Comment

by:AVAHLDICK
ID: 8114057
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
 
LVL 21

Expert Comment

by:ziolko
ID: 8114066
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
 

Author Comment

by:jdorlon
ID: 8114504
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:ziolko
ID: 8115249
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
 
LVL 1

Expert Comment

by:Maximilianop
ID: 8116506
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
 
LVL 21

Accepted Solution

by:
ziolko earned 200 total points
ID: 8117213
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
 

Author Comment

by:jdorlon
ID: 8119614
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question