Solved

Stay On Top

Posted on 2004-05-02
5
365 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Geo, it works (for now).  I hope I don't come across this problem again.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

12 Experts available now in Live!

Get 1:1 Help Now