?
Solved

Form and SW_Hide and HWND_TOPMOST

Posted on 1999-07-25
28
Medium Priority
?
1,185 Views
Last Modified: 2008-02-20
Hi,

I am making a notes program that is sitting next to the clock, so I don't want it to show in the taskbar itself. I use Application.Showmainform := False; for the mainform and that works. The only problem is that all new created forms do show in the taskbar I Tried:

Showwindow(Application.handle, SW_Hide);
Showwindow(Self.Handle, SW_Hide);

In the created new forms (OnFormCreate) procedure
No luck, it still creates a button on the taskbar when a form other than mainform is created. Any solution to this??

And now a little more weird. I set each new form to 'Stayontop' Using this

Application.RestoreTopMosts;
SetWindowsPos(Self.Handle, HWND_TOPMOST,0,0,0,0, SWP_NOACTIVATE + SWP_NOMOVE + SWP_NOSIZE);

But when clicked on a switch (rxswitch) It can also be set to false like so:

Application.NormalizeTopMosts;
SetWindowsPos(Self.Handle, HWND_NOTOPMOST, Etc....);

At Startup all forms stay on top, But when I click on one of them, they all lose 'ontop' capabilities, and when clicking around they sometimes stay on top, than not (even when the switch is set 'ontop'). weird behaviour, If I change the Self.handle to Application.handle, it works again, but then all the forms go to the selected option. But I need to control each form seperate. How does this work best???

Thanks
Marc
0
Comment
Question by:hellfire052497
[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
  • 8
  • 5
  • 4
  • +5
28 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390991
hi hellfire,

maybe its a better way to work with THintwindows
just an idea

meikl

0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390992
Hi hellfire,

to avoid showing buttons on the task bar for each window use the forms BorderStyle property and set it to bsToolWindow.

For the stay-on-top problem: This is a problem I'm also always had fought with. In particular when doing a task switch between my app and others, but this does not apply here... You should rather ask why you need all your forms as topmost forms. Having more than one window topmost is not the intended way to handle windows. Usually there is only one topmost window in an applcation, not more. What is the sense to have more than one?

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390993
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:hellfire052497
ID: 1390994
Hi,

I am using the forms in a Borderless mode (bsnone) because of the use of graphics and special layout. So setting the border again is not an option here.

Setting more than 1 window ontop can be useful, I'm making a "post it notes" program, so it is useful if you can set more than one note ontop

What's a Thintwindow??
And I deleted the question, because the answer is in there, and no one locked it. So no point in keeping it around.

Thanks
Marc
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1390995
Hi Marc, that's not the correct way to delete a question if one of the experts helped you with his comment. Then you really have to ask this expert to lock the question. Meikl chose the polite way. He wanted to give you the chance to say: "Hey, good answer! Go ahead and lock the question to get the points!!". Do you want to punish him for his polite behaviour???

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390996
Marc, Maybe your application does not own the forms.

FormX.Handle must be Applocation.Handle
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390997
hi marc,

first
>And I deleted the question, because the answer is in there, and no one
>locked it. So no point in keeping it around.

if you get an answer by one of the comments there, you should force the expert to answer the q and grade him and not delete the q.

second
>What's a Thintwindow??
a THintwindow is a window to show hints (normally). this windows are staying allways ontop, but cannot contain controls (i've done a try), only text. so that this idea may not be very usefull for you, or?

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390998
hi marc,

a sample, which uses thintwindows, just coded and not all implemented

unit Haftis_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var HaftiList : TList;

procedure TForm1.Button1Click(Sender: TObject);
var
  W : THintwindow;
  R : TRect;
  x,y : Integer;
begin
  W := THintWindow.Create(Application);
  R := W.CalcHintRect(100,edit1.text,nil); //Calculate Layout
  x := StrToInt(edit2.text);               //where should it be placed
  Y := StrToInt(edit3.text);
  R.Top := R.Top + y;
  R.Bottom := R.Bottom + y;
  R.Left := R.Left + x;
  R.Right := R.Right + x;
  W.ActivateHint(R,Edit1.Text);           //Showit
  HaftiList.Add(W);                       //Store for further Actions
end;

initialization
  HaftiList := TList.Create;
finalization
  HaftiList.Free;
end.

have fun

meikl
0
 

Author Comment

by:hellfire052497
ID: 1390999
Hi,

I'll remember this for the future, Thank you for informing me, It wasn't my intention to be impolite, just ignorant.

I create each new form like this (as suggested in the deleted question)

Var
T1 : Tform;
Begin
T1 := TNotesForm.Create(Application);
T1.Show;

So the handle should be correct?, does Windows have another way to remove the form from taskbar?

 
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1391000
I guess you also set FormStyle to fsStayOnTop and according to the Delphi help files this should work:

  with Application do
  begin
    NormalizeTopMosts;
    MessageBox('This should be on top.', 'Look', MB_OK);
    RestoreTopMosts;
  end;


Also try NormalizeAllTopMosts. This one includes the main window too.

Epsylon.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1391001
Have you tried this one?

type TNotesForm = class ...
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  ...

procedure TNotesForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent:=0;
end;

This (together with setting FormStyle on fsStayOnTop) solved my stayOnTop problems...

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391002
>>SetWindowsPos(Self.Handle, HWND_TOPMOST,0,0,0,0,
>>             SWP_NOACTIVATE + SWP_NOMOVE + SWP_NOSIZE);

This is not the way you work with constant value flags... try this..

SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);

this should do it..

..-=ViKtOr=-..
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391003
For the app and the forms try this..

SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

..-=ViKtOr=-..
0
 

Author Comment

by:hellfire052497
ID: 1391004
Hi

Viktornet: The code for the Forms work, They no longer appear on the taskbar (phew), but the suggested code for setwindowpos doesn't work.

Madshi: i'll try your solution tonight, Let you know tomorow.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391005
I was just showing you the proper way of using the flag constants... try Madshi's solution for proper way to do that ;)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391006
btw, hellfire, try this code for setting the form as a Top Window...

function PutOnTop(Form: TForm; ToTop: boolean): boolean;
var
   Status: Integer;
begin
   if ToTop then
       Status := HWND_TOPMOST
   else
       Status := HWND_NOTOPMOST;
   Result := SetWindowPos(Form.Handle, Status, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE)
end;

you can use it like this..

PutOnTop(MyForm, true);

This should work for you just fine..


Good Luck!!

..-=ViKtOr=-..
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1391007
hi, hellfire.

i'm using the trayicon component 4 tray applications. that worx fine.

in order 2 not show your forms as tasks in the taskbar, do as follows:


program Project1;

uses
  Windows,
  Forms,
  ...

{$R *.RES}

procedure HideTaskBar;
Var
 L: Longint;
Begin
 L := GetWindowLong(Application.Handle, GWL_EXSTYLE);
 L := L or WS_EX_TOOLWINDOW;
 SetWindowLong(Application.Handle, GWL_EXSTYLE, L);
End;

begin
  HideTaskBar;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

if u want the trayicon component, post ur email address - i'll send it over 2 ya.

regards,

BlackDeath.

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1391008
oops - sorry, vik.
didn't notice your comment in time.
hellfire - this is the same as vik's.

AshamedDeath.
0
 

Author Comment

by:hellfire052497
ID: 1391009
Hi,

Thanks, It all works now. Viktornet I invite you to lock this question so I can give you the points ;-)

Thanks to all for your valuable input

Take Care
Marc
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391010

0
 
LVL 10

Accepted Solution

by:
viktornet earned 600 total points
ID: 1391011
Thanks!

..-=ViKtOr=-..
0
 

Author Comment

by:hellfire052497
ID: 1391012
Hi,

I guess I cried victory to soon. The ontop still doesn't work, Well it does if all the forms are set to ontop (which they where when I tested the code), then they stay ontop, but when one is switched of, they all lose the ontop status. Isn't there a way to avoid this. I tried with the setwindowpos, and even just a simpel Self.Formstye := fsStayOnTop; All that happens is described above.... Nasty...

Take Care
Marc
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391013
Have you tried a component called TopMost ?
0
 

Author Comment

by:hellfire052497
ID: 1391014
Nope,

Where do I find it???

Thanks
Marc
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391015
hmm, should be on torry pages..

http://www.torry.ru   in #system I thinkç

you just set TopMost.AlwaysOnTop:= True;   and you have it


0
 

Author Comment

by:hellfire052497
ID: 1391016
Hi,

I found it on the delphi super page, I tried it and still no luck...

Thanks though
Marc
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391017
I'll send you.. what's ur email ?
0
 

Author Comment

by:hellfire052497
ID: 1391018
Hi,

I have the component, and another one that also does something like it, I checked their sources and they also use SetWindowPos, and that doesn't work, I tried them both and still the forms will not set them selves ontop.

Thanks anyway for helping
Marc
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

718 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