📄 ch10.htm
字号:
<TD>
<P>Gets an item's display rectangle given its index.</P>
<TR>
<TD>
<pre><font color="#008000">GetToolBarCtrl()</font></pre>
<TD>
<P>Gets a reference to the <font color="#008000">CToolBarCtrl</font> object represented by the <font color="#008000">CToolBar</font> object.</P>
<TR>
<TD>
<pre><font color="#008000">LoadBitmap()</font></pre>
<TD>
<P>Loads the toolbar's button images.</P>
<TR>
<TD>
<pre><font color="#008000">LoadToolBar()</font></pre>
<TD>
<P>Loads a toolbar resource.</P>
<TR>
<TD>
<pre><font color="#008000">SetBitmap()</font></pre>
<TD>
<P>Sets a new toolbar button bitmap.</P>
<TR>
<TD>
<pre><font color="#008000">SetButtonInfo()</font></pre>
<TD>
<P>Sets a button's ID, style, and image number.</P>
<TR>
<TD>
<pre><font color="#008000">SetButtons()</font></pre>
<TD>
<P>Sets the IDs for the toolbar buttons.</P>
<TR>
<TD>
<pre><font color="#008000">SetButtonStyle()</font></pre>
<TD>
<P>Sets a button's style.</P>
<TR>
<TD>
<pre><font color="#008000">SetButtonText()</font></pre>
<TD>
<P>Sets a button's text label.</P>
<TR>
<TD>
<pre><font color="#008000">SetHeight()</font></pre>
<TD>
<P>Sets the toolbar's height.</P>
<TR>
<TD>
<pre><font color="#008000">SetSizes()</font></pre>
<TD>
<P>Sets the buttons' sizes.</P></TABLE>
<P>Normally, you don't need to call the toolbar's methods, but you can get some unusual results when you do, such as the extra high toolbar shown in Figure 10.9. (The buttons are the same size, but the toolbar window is bigger.) This toolbar resulted from
a call to the toolbar object's <font color="#008000">SetHeight()</font> member function. The <font color="#008000">CToolBar</font> class's member functions enable you to perform this sort of toolbar trickery, but use them with great caution.</P>
<A HREF="Lfigs09.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch10/Lfigs09.gif"><b>Fig. 10.9</b></A>
<P><I>You can use a toolbar object's member functions to change how the toolbar looks and acts.</I></P>
<H3><A ID="I8" NAME="I8"><B>Working with Status Bars</B></A></H3>
<P>Status bars are mostly benign objects that sit at the bottom of your application's window, doing whatever MFC instructs them to do. This consists of displaying command descriptions and the status of various keys on the keyboard, including the Caps Lock
and Scroll Lock keys. In fact, status bars are so mundane from the programmer's point of view (at least they are in an AppWizard application) that they aren't even represented by a resource that you can edit like a toolbar. When you tell AppWizard to
incorporate a status bar into your application, there's not much left for you to do.</P>
<P>Or is there? A status bar, just like a toolbar, must reflect the interface needs of your specific application. For that reason, the <font color="#008000">CStatusBar</font> class features a set of methods with which you can customize the status bar's
appearance and operation. Table 10.2 lists the methods along with brief descriptions.</P>
<P><I>Table 10.2—Methods of the </I>CStatusBar<I> Class</I></P>
<TABLE BORDER>
<TR>
<TD>
<P><B>Method</B></P>
<TD>
<P><B>Description</B></P>
<TR>
<TD>
<pre><font color="#008000">CommandToIndex()</font></pre>
<TD>
<P>Gets an indicator's index given its ID.</P>
<TR>
<TD>
<pre><font color="#008000">Create()</font></pre>
<TD>
<P>Creates the status bar.</P>
<TR>
<TD>
<pre><font color="#008000">GetItemID()</font></pre>
<TD>
<P>Gets an indicator's ID given its index.</P>
<TR>
<TD>
<pre><font color="#008000">GetItemRect()</font></pre>
<TD>
<P>Gets an item's display rectangle given its index.</P>
<TR>
<TD>
<pre><font color="#008000">GetPaneInfo()</font></pre>
<TD>
<P>Gets information about an indicator.</P>
<TR>
<TD>
<pre><font color="#008000">GetPaneStyle()</font></pre>
<TD>
<P>Gets an indicator's style.</P>
<TR>
<TD>
<pre><font color="#008000">GetPaneText()</font></pre>
<TD>
<P>Gets an indicator's text.</P>
<TR>
<TD>
<pre><font color="#008000">GetStatusBarCtrl()</font></pre>
<TD>
<P>Gets a reference to the <font color="#008000">CStatusBarCtrl</font> object represented by the <font color="#008000">CStatusBar</font> object.</P>
<TR>
<TD>
<pre><font color="#008000">SetIndicators()</font></pre>
<TD>
<P>Sets the indicators' IDs.</P>
<TR>
<TD>
<pre><font color="#008000">SetPaneInfo()</font></pre>
<TD>
<P>Sets the indicators' IDs, widths, and styles.</P>
<TR>
<TD>
<pre><font color="#008000">SetPaneStyle()</font></pre>
<TD>
<P>Sets an indicator's style.</P>
<TR>
<TD>
<pre><font color="#008000">SetPaneText()</font></pre>
<TD>
<P>Sets an indicator's text.</P></TABLE>
<P>When you create a status bar as part of an AppWizard application, you get a window similar to that shown in Figure 10.10. (To make your own, create a project called <B>Status</B> and accept all the defaults, as you did for the <font
color="#008000">Tool</font> application.) The status bar has several parts, called <I>panes</I>, that display certain information about the status of the application and the system. These panes, which are marked in Figure 10.10, include indicators for the
Caps Lock, Num Lock, and Scroll Lock keys, as well as a message area for showing status text and command descriptions. To see a command description, place your mouse pointer over a button on the toolbar (see Figure 10.11).</P>
<A HREF="Lfigs10.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch10/Lfigs10.gif"><b>Fig. 10.10</b></A>
<P><I>The default MFC status bar contains a number of informative panes.</I></P>
<A HREF="Lfigs11.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch10/Lfigs11.gif"><b>Fig. 10.11</b></A>
<P><I>The message area is used mainly for command descriptions.</I></P>
<P>The most common way to customize a status bar is to add new panes. To add a pane to a status bar, complete these steps:</P>
<ol>
<li><P> Create a command ID for the new pane.</P>
<li><P> Create a default string for the pane.</P>
<li><P> Add the pane's command ID to the status bar's indicators array.</P>
<li><P> Create a command-update handler for the pane.</P>
</ol>
<P>The following sections cover these steps in detail.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -