Board index » delphi » D3 and Always On Top Windows Problem

D3 and Always On Top Windows Problem

HELP! I can't get 'Always on top' windows using Delphi 3.

The purpose of the code below is to intercept the Minimize command,
and replace the application window with a small form 'Minitool' that
acts as a toolbar that floats on top of other applications so that
users can quickly access our program features with a single mouse
click. The code works great when compiled with Delphi 1, but under
3.0, the window does not stay on top of other windows. I've tried
using Minitool.handle in place of (and in addition to) the
Application.handle in the SetWindowPos call, but it still doesn't
work.

-----------------
procedure TMain.WMSysCommand(var Message: TWMSysCommand);
begin
  if (Message.CmdType and $FFF0 = SC_MINIMIZE) then
  Begin                            { Shrink to Mini Tool bar}
    try
      Minitool := TMinitool.Create(Self);
      Hide;  { Hide main form }
      SetWindowPos(Application.Handle, HWND_TOPMOST, 0,0,0,0,
        SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
      Minitool.Showmodal;
      SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0,0,0,0,
        SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
      Show;
    finally
      Minitool.Free;
      Minitool := nil;
      Message.Result := 0;
    end;
    exit;
  End;
  inherited;  {pass on if not minimize}
end;
----------------------
Relative properties of MiniTool include:
  BorderIcons = []
  BorderStyle = bsSingle
  FormStyle = fsStayOnTop
  Position = poDefault

If you have any ideas or suggestions, please let me know.

Thanks.

David Block

CoStar Corporation
Email:  dblockREM...@costar.com

Check us out at http://www.costar.com

www.costar.com
email: dbl...@vdn.com
--------------

 

Re:D3 and Always On Top Windows Problem


David,

try to use minitool.handle in place of application.handle.

Peter Below (TeamB)  100113.1...@compuserve.com)

Re:D3 and Always On Top Windows Problem


On Wed, 10 Dec 1997 21:06:20 +0100, Peter Below

Quote
<100113.1...@compuserve.com> wrote:
>David,

>try to use minitool.handle in place of application.handle.

>Peter Below (TeamB)  100113.1...@compuserve.com)

Been there, done that, no-go. In fact, I've made a simplke test app,
and still can't get it to work when compiled with D3. Doing the same
with D1 works great. Here's a message I posted elsewhereon the net
about this:
---------------------------------------------------
I've gotten several suggestions about the Always On Top problem I'm
having, but none of them solve the problem.

I've created a test app under D1 & D3 that illustrates the problem.
The code works as it's supposed to under Win95 when compiled with D1,
but with D3, Always on Top isn't.

To illustrate:
Create a new application with a Main Form 'FORM1', and a second form
that is NOT auto-created. Call the second form 'Form2'.

Now, add a button to each form. The click event for the button on
FORM2 should simply be:

procedure TForm2.Button1Click(Sender: TObject);
begin
  Close;
end;

The click event for the button on the main form should be:

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    Form2 := TForm2.Create(Self);
    Hide;       { Hide main form }
    SetWindowPos(Application.Handle, HWND_TOPMOST,
      0,0,0,0,
      SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
    Form2.ShowModal;
    SetWindowPos(Application.Handle, HWND_NOTOPMOST,
      0,0,0,0,
      SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
    Show;
  finally
    Form2.Free;
    Form2 := nil;
  end;
end;

With this, the button on FORM1 should cause FORM2 to display as an
ALWAYS on top window. Yet it does not. It is easily covered by other
windows.

So far I've tried:
1) Using Form2.Handle instead of Application.Handle in the
SetWindowPos call
2) Adding a FormShow function to FORM2 to
SetWindowPos(Form2.Handle...)

Neither of these worked. Like everyone else, I'm desperate to solve
this.

Any ideas?

David Block
dbl...@vdn.com

Re:D3 and Always On Top Windows Problem


Quote
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   try
>     Form2 := TForm2.Create(Self);

try Form2 := TForm2.Create(Application);

Krasimir Stoyanov

Re:D3 and Always On Top Windows Problem


Quote
In article <348f3c1e.36243...@news.nothingbutnet.net>, David Block wrote:
> Form2 := TForm2.Create(Self);

Try to change Self to Application here.

Peter Below (TeamB)  100113.1...@compuserve.com)

Re:D3 and Always On Top Windows Problem


On Tue, 09 Dec 1997 21:46:07 GMT, dbl...@vdn.com (David Block) wrote
the magic words:

Quote
>HELP! I can't get 'Always on top' windows using Delphi 3.

>The purpose of the code below is to intercept the Minimize command,
>and replace the application window with a small form 'Minitool' that
>acts as a toolbar that floats on top of other applications so that
>users can quickly access our program features with a single mouse
>click.

I've been looking for a solution for this problem too. The
SetWindowPos seems to "malfunction" in Delphi 3. But I've found
something. Don't know if it's according to the rules of proper
programming, but it works. The only con is that it stays on top of
your windows95 taskbar too. Not a problem for me though....

(* *********************************************************
   ********************************************************* *)

private
 procedure CreateParams(var Params: TCreateParams); override;
public
 { Public declarations }
end;

implementation

uses unit_configure, unit_diversen, unit_main;

{$R *.DFM}

procedure TFrmFloat.createparams(var params:tcreateparams);
begin
 // override the creation parameters and set the window owner to the
 //desktop window;
 inherited createparams(params);
 params.wndparent:=getdesktopwindow;
end;

(* *********************************************************
   ********************************************************* *)

The only "problem" is that the window appears in the win95 taskbar
too. To prevent this, use:

(* *********************************************************
   ********************************************************* *)

procedure TFrmFloat.FormShow(Sender: TObject);
begin
 SetWindowLong (Self.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;

(* *********************************************************
   ********************************************************* *)

If someone has a better solution or knows a way to make SetWindowsPos
work, please post.

Hope this solutions works for you!

HTH, Phranc
--
=================
The optimist thinks this is the best of all possible worlds.
The pessimist fears it is true.
=================

http://huizen.dds.nl/~phranc/

Other Threads