⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq60.htm

📁 C++builder学习资料C++builder
💻 HTM
字号:


<HTML>

<HEAD>

   <TITLE>Force an MDI child to close rather than minimizing</TITLE>

   <META NAME="Author" CONTENT="Harold Howe">

</HEAD>

<BODY BGCOLOR="WHITE">



<CENTER>

<TABLE  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">



<TR>

<TD>








<H3>

Force an MDI child to close rather than minimizing

</H3>



<P>

When you close an MDI child, you may notice that the child form minimizes rather than

actually closing. <TT>TCustomForm::Close</TT> explains what is going on.

</P>

<pre>

<b>void</b> <b>__fastcall</b> TCustomForm<b>:</b><b>:</b>Close<b>(</b><b>)</b>

<b>{</b>

    <b>...</b>

    <b>if</b><b>(</b>FormStyle <b>==</b> fsMDIChild<b>)</b>

    <b>{</b>

        <b>if</b> BorderIcons<b>.</b>Contains<b>(</b>biMinimize<b>)</b><b>)</b>

            CloseAction <b>=</b> caMinimize

        <b>else</b>

            CloseAction <b>=</b> caNone

    <b>}</b>

    <b>...</b>

    <b>if</b> <b>(</b>FOnClose<b>)</b>

        FOnClose<b>(</b><b>this</b><b>,</b> CloseAction<b>)</b><b>;</b>

    <b>...</b>

<b>}</b>

</pre>

<P>

<TT>CloseAction</TT> is an enumerated variable that tells <TT>TForm</TT> how you want the

form to close. Closing can mean several different things. You may want to hide

the form, but keep the form object intact for later user. You may want to completely

destroy the window and the form object, or you may want to do nothing at all.

<TT>CloseAction</TT> controls how the form will respond to the close command. The possible

values are listed in <TT>FORMS.HPP.</TT>

</P>

<pre>

    <b>enum</b> TCloseAction <b>{</b> caNone<b>,</b> caHide<b>,</b> caFree<b>,</b> caMinimize <b>}</b><b>;</b>

</pre>

<P>

For forms that are not MDI children, <TT>CloseAction</TT> is initialized to <TT>caHide</TT>.

Notice that <TT>TCustomForm::Close</TT> sets <TT>CloseAction</TT> to <TT>caMinimize</TT>

if the MDI child form has a minimize button in its title bar. MDI children cannot be hidden

(a restriction imposed by Windows). The VCL minimizes the form to circumvent the restriction.

</P>

<P>

If you want to close the MDI child instead of minimizing it, write an <TT>OnClose</TT>

handler for the MDI child that sets <TT>CloseAction</TT> to <TT>caFree</TT>. The VCL passes

the <TT>CloseAction</TT> variable to your <TT>OnClose</TT> handler so you can have the last

word in how the VCL should react. The code below demonstrates what to do.

</P>

<pre>

<b>void</b> <b>__fastcall</b> TMDIChild<b>:</b><b>:</b>FormClose<b>(</b>TObject <b>*</b>Sender<b>,</b> TCloseAction <b>&</b>Action<b>)</b>

<b>{</b>

    Action <b>=</b> caFree<b>;</b>

<b>}</b>

</pre>

<BR>

<P>

<B>Note:</B> Setting <TT>CloseAction</TT> to <TT>caFree</TT> forces the VCL to destroy

the MDI child window and free the form object associated with the child window. Since the form

is being destroyed, don't dereference the MDI child's form pointer after you close the window.

Also, don't attempt to delete the pointer a second time.

</P>



</TD> </TR>



</TABLE>

</CENTER>

</BODY>

</HTML>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -