Jump to content
Tom F

fsStayOnTop sometimes doesn't work when Alt-tabbing

Recommended Posts

In an app, some of our VCL Forms have FormStyle := fsStayOnTop assigned in the Object Inspector.

 

Occasionally we temporarily change it to fsNormal when we're popping up a system font or color dialog box.

Sometimes, (but so far unpredictably) including sometimes when Alt-tabbing back to our app, our on-top window is not visible.

 

Sometimes the user can make it visible again with some combination of Alt-Tabs, and minimizing then un-minimizing the app on the Taskbar.

As I understand it, this isn't unusual, and that under Windows, Microsoft doesn't guarantee that fsStayOnTop is reliable, given various contention issues, etc.

I'm looking for a way to reduce the frequency of this problem in our app.

What is the current "best practice" is in this area?

There are a smattering of posts on the web on this topic, some go back decades.

 

One of the posts suggests overriding CreatParams as shown below.  Rather than being a total script-kiddie, is the code below a reasonable approach, or is it just the equivalent of setting FormStyle := fsStayOnTop?

 

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

 

Share this post


Link to post
6 minutes ago, Tom F said:

 


procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FormStyle := fsStayOnTop; // works for me
  // SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); // works for others
end;

 

My way.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×