How do I add a form to the taskbar?

12 views
Skip to first unread message

zhoudi

unread,
Apr 22, 2005, 9:43:42 PM4/22/05
to
How do I add a form to the taskbar and the form is not minimized when then
main form was minimized?

I have try the code, but I'm failed:


type
TMyForm = class(TForm)
public
procedure CreateParams(var Params: TCreateParams); override;
end;

implementation

procedure TMyForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;
end;


Jaelani C. U.

unread,
Apr 24, 2005, 5:37:14 PM4/24/05
to
>"zhoudi" <zho...@ez.hb.cninfo.net> wrote in message
>news:4269...@newsgroups.borland.com...

> How do I add a form to the taskbar and the form is not minimized when then
> main form was minimized?
[-snip-]

So you have more than one form. Right? Let's call it MainForm and Form2.
In the project file (the DPR), add these two lines:

Application.ShowMainForm:= false;
Application.OnIdle:= AppInit; //this event is not accessible via object
inspector


And in the Form2 unit, add a new protected method to the TForm2:

function TForm2.AppInit(Sender: TObject; var Done: Boolean);
begin
Application.OnIdle:= nil;
Form2.showmodal;
MainForm.close; //close application if Form2 is closed
end;


Hope that works for you.

_____
Jaelani


Jaelani C. U.

unread,
Apr 24, 2005, 5:39:48 PM4/24/05
to
Oops... forgot to tell you to add the lines below BEFORE the
"Application.Run;" line.

zhoudi

unread,
Apr 25, 2005, 2:32:14 AM4/25/05
to
Thank you, Mr. Jaelani.
My purpose is, Form2 and main Form was shown on screen at same time,
Form2 is created by main Form(for example, press a button to create Form2
from main Form) and it must be a non modal window and have a taskbar button.
That is, Form2 and main Form is unaided like chat window and main window of
MSN Messenger.
How can I do?


"Jaelani C. U." <jael...@gmx.net> 写入消息新闻:426c...@newsgroups.borland.com...

Deepak Shenoy (TeamB)

unread,
Apr 25, 2005, 4:45:32 AM4/25/05
to
zhoudi wrote:

> How do I add a form to the taskbar and the form is not minimized when
> then main form was minimized?
>
> I have try the code, but I'm failed:

The code you've given works for me - Windows XP Prof. What OS are you
using?

--
Deepak Shenoy (TeamB)
Agni Software (http://www.agnisoft.com)
Blog: http://shenoyatwork.blogspot.com

Jaelani C. U.

unread,
Apr 25, 2005, 6:21:07 PM4/25/05
to
>"zhoudi" <zho...@info21.com.cn> wrote in message
>news:426c...@newsgroups.borland.com...

> Thank you, Mr. Jaelani.
> My purpose is, Form2 and main Form was shown on screen at same time,
> Form2 is created by main Form(for example, press a button to create Form2
> from main Form) and it must be a non modal window and have a taskbar
> button. That is, Form2 and main Form is unaided like chat window and main
> window of MSN Messenger.
> How can I do?

Well, your code already works.
It works on Windows Xp, as tested by Deekpak Shenoy.
I've test it on Windows 98, and it works too.

_____
Jaelani


zhoudi

unread,
Apr 25, 2005, 9:02:41 PM4/25/05
to
This is my code, it works for me but there are a problem:
Main Form becomes a foreground window automatically when the Form2
overlapped with main Form and a hint was displayed on Form2
How can I round it?

// Project

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

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

//---------------- Main Form
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses unit2;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
wnd2: TForm2;
begin
wnd2:=TForm2.Create(nil);
wnd2.Show;
end;

end.

//------------------- Form2, it will be created by main Form

unit Unit2;

interface

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

type
TForm2 = class(TForm)
RichEdit1: TRichEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }


procedure CreateParams(var Params: TCreateParams); override;
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle:=Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent:= GetDesktopWindow;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Free;
end;

end.

"Deepak Shenoy (TeamB)" <non...@noname.com> 写入消息新闻:426cae2c$1...@newsgroups.borland.com...

Deepak Shenoy (TeamB)

unread,
Apr 26, 2005, 1:03:27 AM4/26/05
to
zhoudi wrote:

> This is my code, it works for me but there are a problem:
> Main Form becomes a foreground window automatically when the Form2
> overlapped with main Form and a hint was displayed on Form2
> How can I round it?

Create a class like this:

TMyHintWindow = class( THintWindow )
public
procedure ActivateHint(Rect: TRect; const AHint: string); override;
end;
...
{ TMyHintWindow }

procedure TMyHintWindow.ActivateHint(Rect: TRect; const AHint: string);
begin
Self.ParentWindow := 0;
inherited;
end;

...

initialization
HintWindowClass := TMyHintWindow;

That should work.


Now, as an aside: Do NOT do this:


> procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
> begin
> Free;
> end;

Set Action := caFree; instead.

zhoudi

unread,
Apr 26, 2005, 4:18:40 AM4/26/05
to
Thank you for your answer, it help me to fix about hint. But there is a same
problem when I called a OpenDialog or opened a custom dialog from Form2,
what should I do ?


"Deepak Shenoy (TeamB)" <non...@noname.com> 写入消息新闻:426d...@newsgroups.borland.com...

Deepak Shenoy (TeamB)

unread,
Apr 26, 2005, 6:58:00 AM4/26/05
to
zhoudi wrote:

> Thank you for your answer, it help me to fix about hint. But there is
> a same problem when I called a OpenDialog or opened a custom dialog
> from Form2, what should I do ?
>

(Note: please trim your comments)

Your problems seems to be because the application's handle is getting
all sorts of messages and it's enabling your main form instead.

A solution is to make your main form ALSO an appwindow, and remove the
appwindow style from the Application. Do this for your main form:

1) override CreateParams just like you did for your sub form, and add
the WS_EX_APPWINDOW style
2) In the FormCreate procedure of the main form, do this:
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle,GWL_EXSTYLE)
and not WS_EX_APPWINDOW
or WS_EX_TOOLWINDOW);

then you don't even need that Hint override which I'd talked about
earlier.

zhoudi

unread,
Apr 26, 2005, 10:15:47 PM4/26/05
to
Did you remember MSN Messenger? its chat window seems as if unaided with
main window, main window and chat window have their own taskbar button and
don't impact each other. it's easy to implement in VC ( just need set parent
of new window(created by main window) and main window to Desktop ). In
delphi, they looks too difficult to shake Application window off. I have
tried many ways(include the code you gave), but they all couldn't really
implement the effect like MSN Messenger. Have any better ways? Thank you.


Deepak Shenoy (TeamB)

unread,
Apr 27, 2005, 1:58:58 AM4/27/05
to
zhoudi wrote:

I don't see a problem now if you make the MainForm an Appwindow and
remove the AppWindow style from the Application. There are many
applications which are "messenger" clients - jabber clients for
example, and some "universal" ones too (though I don't recall their
names now) - so I'm assuming there must be ways to solve these issues.
Can you let us know what issues you are facing?

zhoudi

unread,
Apr 27, 2005, 5:31:03 AM4/27/05
to
Sorry, my english is so bad. :)

In fact, I'm writing a instant messenger client. I want a chat window
and main window must be like this:
1). caht window is created by main window and chat window has taskbar
button.
2). when the main window is maximized or minimized, chat window's status
is not changed and its taskbar button kept on
3). just main window and chat window has taskbar button, application
window has never had taskbar button
4). main window don't become a foreground window automatically when chat
window open a dialog or display a hint
5). application window is not minimized to Desktop yet.

Could you help me? Thank you.

"Deepak Shenoy (TeamB)" <non...@noname.com> 写入消息新闻:426f...@newsgroups.borland.com...

Deepak Shenoy (TeamB)

unread,
Apr 27, 2005, 8:12:34 AM4/27/05
to
zhoudi wrote:

> Sorry, my english is so bad. :)
>
> In fact, I'm writing a instant messenger client. I want a chat
> window and main window must be like this:
> 1). caht window is created by main window and chat window has
> taskbar button.
> 2). when the main window is maximized or minimized, chat window's
> status is not changed and its taskbar button kept on
> 3). just main window and chat window has taskbar button,
> application window has never had taskbar button
> 4). main window don't become a foreground window automatically
> when chat window open a dialog or display a hint
> 5). application window is not minimized to Desktop yet.

All of this is possible if you
a) Have the chat window created with the WS_EX_APPWINDOW style (you
already have done this)
b) Create the main window ALSO with the WS_EX_APPWINDOW style
c) Remove the WS_EX_APPWINDOW style from the Application window (i've
given code earlier in this thread)

Also don't create the chat window with Owner as Application , create it
with owner=nil.

Reply all
Reply to author
Forward
0 new messages