📄 faq3.htm
字号:
<HTML>
<HEAD>
<TITLE>Minimize or restore the program in code</TITLE>
<META NAME="Author" CONTENT="Harold Howe">
</HEAD>
<BODY BGCOLOR="WHITE">
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">
<TR>
<TD>
<H3>
Minimize or restore the program in code<BR>
</H3>
<BR>
<P>
You can achieve this by using one of three different methods.
First, you can send a windows message to to the main form's <TT>Handle</TT> property or to
<TT>Application->Handle</TT>. The message would be <TT>WM_SYSCOMMAND</TT>
with <TT>wParam</TT> set to <TT>SC_MINIMIZE</TT> or <TT>SC_RESTORE</TT>.
You can send the message by calling the <TT>SendMessage</TT> API function.
</P>
<pre>
<font color="navy">// To minimize, pass SC_MINIMIZE as the WPARAM</font>
SendMessage<b>(</b>Application<b>-></b>Handle<b>,</b> WM_SYSCOMMAND<b>,</b> SC_MINIMIZE<b>,</b> <font color="blue">0</font><b>)</b><b>;</b>
<font color="navy">// To restore, pass SC_RESTORE as the WPARAM</font>
SendMessage<b>(</b>Application<b>-></b>Handle<b>,</b> WM_SYSCOMMAND<b>,</b> SC_RESTORE<b>,</b> <font color="blue">0</font><b>)</b><b>;</b>
</pre>
<P>
The second method is to call the <TT>ShowWindow</TT> API function. You must pass the <TT>ShowWindow</TT> function the
handle of the global <TT>Application</TT> object. If you pass it the handle of the main form, the main form will
minimize to the desktop instead of minimizing to the taskbar.
</P>
<pre>
<font color="navy">// To minimize, pass SW_MINIMIZE to ShowWindow</font>
ShowWindow<b>(</b>Application<b>-></b>Handle<b>,</b> SW_MINIMIZE<b>)</b><b>;</b>
<font color="navy">// To restore, pass SW_RESTORE to ShowWindow</font>
ShowWindow<b>(</b>Application<b>-></b>Handle<b>,</b> SW_RESTORE<b>)</b><b>;</b>
</pre>
The third method is to call the <TT>Minimize</TT> or <TT>Restore</TT> functions of
the global <TT>Application</TT> object. <TT>Minimize</TT> and <TT>Restore</TT> are methods
of <TT>TApplication</TT>.</P>
<pre>
<font color="navy">// To minimize the app, call Minimize</font>
Application<b>-></b>Minimize<b>(</b><b>)</b><b>;</b>
<font color="navy">// To restore the app, call Restore</font>
Application<b>-></b>Restore<b>(</b><b>)</b><b>;</b>
</pre>
<P>
The <TT>Application</TT> methods are easy to use, but sending the <TT>WM_SYSCOMMAND</TT> message is more
versatile. In addition to minimizing and restoring, the <TT>WM_SYSCOMMAND</TT>
message allows you to maximize the application (restoring may or may not
maximize the form), change the cursor to the help cursor, scroll the
program, move a window, size a window, or simulate Alt-TAB my moving to
the next window. Keep in mind that some of these functions, such as
sizing and moving, are better served by the <TT>SetWindowPos</TT> API function.
</P>
<P>
Although calling <TT>ShowWindow</TT> does work, you probably don't want to use it to minimize
or restore your program. <TT>ShowWindow</TT> causes the minimization animation to appear while the
hidden application window is being minimized. This looks somewhate goofy, because the animation is off
center from the position of the mainform of the program.
</P>
</TD> </TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -