Solved

Stay On Top

Posted on 2004-05-02
5
370 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 168
Run video youtube webbrowse 10 74
How to renew a Delphi rad-studio licence? 5 77
Delphi: barcode reading on android platform 1 76
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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