Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Guarantee and reliable StayOnTop ?

Status
Not open for further replies.

mickeyfeldman

Programmer
Nov 4, 2005
5
0
0
CA
Guarantee and reliable StayOnTop ?

The Delphi docs recommend against changing the formstyle while a program is running.

My application (App A) communicates with another application (App B) on the same PC via TCP. I do not have access to the source for App B. App A generally appears as a wide control and menu bar at the top of the screen and stays on top of App B. When App A passes control to App B, App A hides; when App A receives a message from App B it makes itself visible again. So far, no problem.

App A also receives data input from an external device (serial port) at arbitrary times. A user may be in attendance or the process may run automatically. When external data is received, other forms are launched by App A for the benefit of the possible user. If there is a user, and if that user clicks on App B, App A becomes inactive but Stays On Top as intended. By setting the formstyle of all my forms to fsStayOnTop, and resetting this property in my main form Activate and DeActivate events, I can generally get 90% of the behavior I'm looking for.

However, 1) Trying to set formstyle in the OnResize event causes App A to disappear entirely but continue running as a process visible only in the Windows Task Manager, which must be used to kill it. 2) if the user minimizes App A, it then loses its StayOnTopness until it is closed and restarted. 3) I had a button which iconized App A to the tool bar using Shell_NotifyIcon, and which worked correctly before I tried to force App A to stay on top. This now causes App A to place its icon in the system tray, after which the icon promptly disappears and only the Task Manager accessible process is available.

Is there a straightforward (or hey, any) way to force App A to always be on top except when it is minimized intentionally by the user or hidden entirely under program control, to maintain this behavior regardless of what actions the user may take, regardless of whether it displays forms other than its main form, and regardless of which App has focus?

Thanks for any answers
 
Have you tried the BringToFront command?

Maybe you can add a timer, set the timer interval to 500 or so and do something like this:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (form1.WindowState <> wsMinimized) then
form1.BringToFront;
end;

You can then also add a check to see if it is hidden.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Unfortunalely, the issue is not that the app is minimized or hidden, the issue is that it loses its 'StayOnTopness', and I cannot retore it to that state.

I have tried many combinations of :

BringToFront
SetWindowPos
SetForegroundWindow
BringWindowToTop
SetZOrder
ShowWindow
in addition to setting fsStayOnTop

for both the form(s) and the application, as well as directly posting Windows Messages, setting focus...

I have called these procedures in every combination of event that might occur because of or immediately after the form(s) or application would have any reason to lose its 'StayOnTopness' - form or Application minimize, resize, paint, restore, activate, deactive....

Some of these combinations are disasterous, as described in my original post. Most simply don't solve the problem, which is that when the app is minimized, or sometimes when a subsidary form is shown and another app gets focus, then my app loses its 'StayOnTopness' entirely, until it is restarted.

I don't doubt that there is a set of logical rules about how Windows applications interact and how 'StayOnTopness' might lose its stickyness, but I don't have enough depth of knowledge of Windows to know just what they are.

If anyone knows of a discussion of this anywhere other than the descriptions of the individual Windows API calls, I'd love to know about it.

Thanks

 
What about showing your form modally. Does that help?

What about when the other form has focus, you try Form1.BringToFront (if you haven't tried that already)




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Are you saying that your application needs to pop up in front of another running application over which you have no control?
Might the problem be that the other application is also attempting to 'Stay on Top'?


Steve: Delphi a feersum engin indeed.
 
There is no question that the other app is at least briefly throwing up a small stay-on-top status form. My understanding from the Windows documentation was that several forms/applications can all be 'StayOnTop', and in this case there was no guarantee which would end up on top, or rather, this was generally determined by user actions (selecting an app). However, if I set or restore the StayOnTopness to my form, and then send it to the front, it should then show on top of that other form, no?

If the rule is that 'when there are two or more TopMost forms, you cannot force your form to the top, it's strictly under the control of the user', then I'm out of luck unless I can get the other application to synchronously cooperate. If this is the case, it would be nice to have confimation so that I stop trying to do the impossible.

 
this may help


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
protected
procedure CreateParams(var Params: TCreateParams); override;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

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

end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top