[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Stay On Top

Hello experts,

I'm sure you've seen plenty of questions regarding this topic, and I have read many solutions, but I still have a problem.  I have set the 'FormStyle' property in my form to 'fsStayOnTop', and in addition to that added the following code to my constructor to make sure my main window stays on top

  SetWindowPos(handle, hwnd_TopMost,0,0,0,0, swp_NoMove or swp_NoSize);

But, apparently there is an uncaught exception in my application that doesn't stop my program from executing, but causes my app. to lose the 'stay on top' capability.  Has anyone seen anything like this before?  Is there a solution, other than 'make sure you catch all exceptions'?  I am looking for the bug in my program so I can catch it, but I would like to prevent this from happening again.

Thanks,

danny
0
dannyguindi
Asked:
dannyguindi
1 Solution
 
ceoworksCommented:
Hi Danny,

After you set your form StayOnTop and use SetWindowPos are you sure that you are not setting any other form as StayOnTop ?

Rgds,

Oktay
0
 
Ivanov_GCommented:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure OnShowWindow(var Msg : TWMShowWindow); message WM_SHOWWINDOW;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.OnShowWindow(var Msg: TWMShowWindow);
begin
  //
  if not Msg.Show then
    begin
      Msg.Result := 0;
      Exit;
    end
  else
    inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FormStyle := fsStayOnTop;
end;

end.
0
 
geobulCommented:
Hi,

Try this:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure OnTop(SendeR: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.OnTop(SendeR: TObject);
begin
  SetWindowPos(handle, hwnd_TopMost,0,0,0,0, swp_NoMove or swp_NoSize); // I moved your code here instead of in the constructor
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnDeactivate := OnTop;
end;

Regards, Geo
0
 
jesurfCommented:
Hi!

I did put a component called TFormTopmost (i belive) in one application. I downloaded this component from internet.
It permit you to select manually topmost or no while the application is running. Of course you can selet it programming.

I try give you more information about this another day
0
 
dannyguindiAuthor Commented:
Thanks Geo, it works (for now).  I hope I don't come across this problem again.
0

Featured Post

Industry Leaders: 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!

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