Solved

Stay On Top

Posted on 2004-05-02
5
368 Views
Last Modified: 2010-08-05
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
Comment
Question by:dannyguindi
5 Comments
 
LVL 4

Expert Comment

by:ceoworks
ID: 10973607
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
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10976257
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
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 10976431
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
 

Expert Comment

by:jesurf
ID: 10991116
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
 

Author Comment

by:dannyguindi
ID: 10999857
Thanks Geo, it works (for now).  I hope I don't come across this problem again.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now