• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1210
  • Last Modified:

Form and SW_Hide and HWND_TOPMOST

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
hellfire052497
Asked:
hellfire052497
  • 8
  • 5
  • 4
  • +5
1 Solution
 
kretzschmarCommented:
hi hellfire,

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

meikl

0
 
LischkeCommented:
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
 
kretzschmarCommented:
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
hellfire052497Author Commented:
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
 
MadshiCommented:
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
 
EpsylonCommented:
Marc, Maybe your application does not own the forms.

FormX.Handle must be Applocation.Handle
0
 
kretzschmarCommented:
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
 
kretzschmarCommented:
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
 
hellfire052497Author Commented:
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
 
EpsylonCommented:
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
 
MadshiCommented:
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
 
viktornetCommented:
>>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
 
viktornetCommented:
For the app and the forms try this..

SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

..-=ViKtOr=-..
0
 
hellfire052497Author Commented:
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
 
viktornetCommented:
I was just showing you the proper way of using the flag constants... try Madshi's solution for proper way to do that ;)
0
 
viktornetCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
oops - sorry, vik.
didn't notice your comment in time.
hellfire - this is the same as vik's.

AshamedDeath.
0
 
hellfire052497Author Commented:
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
 
bryan7Commented:

0
 
viktornetCommented:
Thanks!

..-=ViKtOr=-..
0
 
hellfire052497Author Commented:
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
 
bryan7Commented:
Have you tried a component called TopMost ?
0
 
hellfire052497Author Commented:
Nope,

Where do I find it???

Thanks
Marc
0
 
bryan7Commented:
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
 
hellfire052497Author Commented:
Hi,

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

Thanks though
Marc
0
 
bryan7Commented:
I'll send you.. what's ur email ?
0
 
hellfire052497Author Commented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 8
  • 5
  • 4
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now