📄 faq9.htm
字号:
<HTML>
<HEAD>
<TITLE>Create forms that minimize to the taskbar</TITLE>
<META NAME="Author" CONTENT="Harold Howe">
</HEAD>
<BODY BGCOLOR="WHITE">
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">
<TR>
<TD>
<H3>
Create forms that minimize to the taskbar
</H3>
<BR>
<P>
Many Windows programs create secondary forms that minimize
to the taskbar. For example, MS Exchange opens a new window when you read a
mail message, and these windows minimize to the taskbar. Netscape creates
different windows for its browser, news reader, and mail reader, and each
window minimizes to the taskbar. Come to think of it, having forms that minimize
to the desktop isn't too useful, and not many apps seem to work that way.
</P>
<P>
A window will minimize to the taskbar if its extended window style contains
the <TT>WS_EX_APPWINDOW</TT> style. By default, secondary forms do not have this
style set. You can make a form minimize to the taskbar by overriding the
<TT>CreateParams</TT> function and altering the extended windows style. Use this
code from the secondary form.
</P>
<pre>
<b>void</b> <b>__fastcall</b> TForm2<b>:</b><b>:</b>CreateParams<b>(</b>TCreateParams <b>&</b>Params<b>)</b>
<b>{</b>
TForm<b>:</b><b>:</b>CreateParams<b>(</b>Params<b>)</b><b>;</b>
Params<b>.</b>ExStyle <b>|=</b> WS_EX_APPWINDOW<b>;</b>
<b>}</b>
</pre>
<P>
In addition to making a form minimize to the taskbar, you will also want to change
the owner of the secondary form. By owner, I mean the owner window of the form in API
terms, not the VCL owner. The hidden application window owns all forms in a C++Builder
program. The OS hides all owned windows when their owner window is hidden or minimized.
When you create an independent form that minimizes to the taskbar, this behavior will
seem awkward. To fix the problem, set the <TT>WndParent</TT> member of <TT>TCreateParams</TT>
to the result of <TT>GetDesktopWindow</TT>. This makes the desktop the owner of the form,
and prevents the form from being hidden when you minimize the main form of the program.
</P>
<pre>
<b>void</b> <b>__fastcall</b> TForm2<b>:</b><b>:</b>CreateParams<b>(</b>TCreateParams <b>&</b>Params<b>)</b>
<b>{</b>
TForm<b>:</b><b>:</b>CreateParams<b>(</b>Params<b>)</b><b>;</b>
Params<b>.</b>ExStyle <b>|=</b> WS_EX_APPWINDOW<b>;</b>
Params<b>.</b>WndParent <b>=</b> GetDesktopWindow<b>(</b><b>)</b><b>;</b>
<b>}</b>
</pre>
<P>
Remember that changing the <TT>WndParent</TT> member of <TT>CreateParams</TT> does not affect
who deletes the form object.
</P>
<BR>
<TABLE BORDER=1 CELLPADDING=10 CELLSPACING=0 WIDTH="100%">
<TR> <TD colspan = 2><B>Downloads for this FAQ</B> </TD> </TR>
<TR> <TD><TT><A HREF="download/appwin.zip" >appwin.zip </A></TT></TD> <TD>BCB3 project with a mainform that creates multiple secondary forms that minimize to the taskbar. </TD> </TR>
<TR> <TD><TT><A HREF="download/appwinx.zip">appwinx.zip</A></TT></TD> <TD>Same project. Includes an EXE so you can run the project without compiling.</TD> </TR>
</TABLE>
</TD> </TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -