Board index » delphi » How to force a form to display its own button in the windows taskbar

How to force a form to display its own button in the windows taskbar

Hello all,

I want to build an application with a user interface similar to MS Outlook -
One main form, and each "detail form" shall be shown non-modal and have its
own button in the windows taskbar.

I managed it to have the form display a button in the taskbar by overriding
the CreateParams method and settings the Form.ParentWnd = 0, which works
almost fine, but there is one problem:

When I want to show a modal dialog from a detail form, the main form is
always displayed and becomes the active form of my application. Is there any
way to achieve what I want without having these problems with modal forms?

Thanks in advance

Bastian Bauwens

 

Re:How to force a form to display its own button in the windows taskbar


Quote
"Bastian Bauwens" <bbauw...@aixware.de> wrote in message

news:3b38a99e_1@dnews...

Quote
> Hello all,

> I want to build an application with a user interface similar to MS
Outlook -
> One main form, and each "detail form" shall be shown non-modal and have
its
> own button in the windows taskbar.

> I managed it to have the form display a button in the taskbar by
overriding
> the CreateParams method and settings the Form.ParentWnd = 0, which works
> almost fine, but there is one problem:

> When I want to show a modal dialog from a detail form, the main form is
> always displayed and becomes the active form of my application. Is there
any
> way to achieve what I want without having these problems with modal forms?

> Thanks in advance

I found this somewhere on the web (don't remember where):

To add a taskbar button for a specific application window, you need to
override the CreateParams method of TForm and add WS_EX_APPWINDOW to the
window's extended style:

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

implementation

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

This will add the taskbar button for your form, but there are a few other
minor details to handle.  Most obviously, your form still receives
minimize/maximize that get sent to the parent form (the main form of the
application).  In order to avoid this, you can install a message handler for
WM_SYSCOMMAND by adding a line such as:

procedure WMSysCommand(var Msg: TMessage); WM_SYSCOMMAND;

procedure TParentForm.WMSysCommand(var Msg: TMessage);
begin
  if Msg.wParam = SC_MINIMIZE then
  begin
    // Send child windows message, don't
    // send to windows with a taskbar button.
  end;
end;

Note that this handler goes in the PARENT form of the one you want to behave
independantly of the rest of the application, so as to avoid passing on the
minimize message. You can add similar code for SC_MAXIMIZE, SC_RESTORE, etc.

Have a great day!

Ernest
(efairch...@home.com)
_____________________
"You will never find anybody who can give you a clear and compelling reason
why we observe daylight savings time." -- Dave Barry

Visit my website at http://www.public.asu.edu/~ernestf

Re:How to force a form to display its own button in the windows taskbar


Quote
In article <3b38a99e_1@dnews>, Bastian Bauwens wrote:
> I want to build an application with a user interface similar to MS Outlook -
> One main form, and each "detail form" shall be shown non-modal and have its
> own button in the windows taskbar.
> I managed it to have the form display a button in the taskbar by overriding
> the CreateParams method and settings the Form.ParentWnd = 0, which works
> almost fine, but there is one problem:
> When I want to show a modal dialog from a detail form, the main form is
> always displayed and becomes the active form of my application. Is there any
> way to achieve what I want without having these problems with modal forms?

Yes. In your overriden CreateParams method remove the line that moifies
ParentWnd and instead add the WS_EX_APPWINDOW exstyle:

procedure TForm2.CreateParams(Var params: TCreateParams);
  begin
    inherited CreateParams( params );
    params.ExStyle := params.ExStyle OR WS_EX_APPWINDOW;
  end;
end.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:How to force a form to display its own button in the windows taskbar


Hi Ernest,

thanks for the tip, it works, but I have some problems in understanding what
I have to do with the messages that are sent to the main form. Can you
perhaps give me an example for that?

TIA

Bastian

"Ernest Fairchild" <efairch...@home.com> schrieb im Newsbeitrag
news:3b38c8b4$1_1@dnews...

Quote
> "Bastian Bauwens" <bbauw...@aixware.de> wrote in message
> news:3b38a99e_1@dnews...
> > Hello all,

> > I want to build an application with a user interface similar to MS
> Outlook -
> > One main form, and each "detail form" shall be shown non-modal and have
> its
> > own button in the windows taskbar.

> > I managed it to have the form display a button in the taskbar by
> overriding
> > the CreateParams method and settings the Form.ParentWnd = 0, which works
> > almost fine, but there is one problem:

> > When I want to show a modal dialog from a detail form, the main form is
> > always displayed and becomes the active form of my application. Is there
> any
> > way to achieve what I want without having these problems with modal
forms?

> > Thanks in advance

> I found this somewhere on the web (don't remember where):

> To add a taskbar button for a specific application window, you need to
> override the CreateParams method of TForm and add WS_EX_APPWINDOW to the
> window's extended style:

> type
>   TMyForm = class(TForm)
>     protected
>       procedure CreateParams(var Params: TCreateParams);
>     end;

> implementation

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

> This will add the taskbar button for your form, but there are a few other
> minor details to handle.  Most obviously, your form still receives
> minimize/maximize that get sent to the parent form (the main form of the
> application).  In order to avoid this, you can install a message handler
for
> WM_SYSCOMMAND by adding a line such as:

> procedure WMSysCommand(var Msg: TMessage); WM_SYSCOMMAND;

> procedure TParentForm.WMSysCommand(var Msg: TMessage);
> begin
>   if Msg.wParam = SC_MINIMIZE then
>   begin
>     // Send child windows message, don't
>     // send to windows with a taskbar button.
>   end;
> end;

> Note that this handler goes in the PARENT form of the one you want to
behave
> independantly of the rest of the application, so as to avoid passing on
the
> minimize message. You can add similar code for SC_MAXIMIZE, SC_RESTORE,
etc.

> Have a great day!

> Ernest
> (efairch...@home.com)
> _____________________
> "You will never find anybody who can give you a clear and compelling
reason
> why we observe daylight savings time." -- Dave Barry

> Visit my website at http://www.public.asu.edu/~ernestf

Other Threads