Solved

Stay On Top

Posted on 2004-05-02
5
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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