📄 c++ builder 程序设计实用教程 - 2_6 状态条组件 - 张晋 - 17xie.htm
字号:
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>Panels = <></SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>SimplePanel = True</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>end</SPAN></P>
<P class=a1><SPAN lang=EN-US>end</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在本程序中用到了</SPAN><SPAN
lang=EN-US>1</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个</SPAN><SPAN
lang=EN-US>Panel</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件、</SPAN><SPAN
lang=EN-US>3</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个</SPAN><SPAN
lang=EN-US>SpeedButton</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件、</SPAN><SPAN
lang=EN-US>3</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个</SPAN><SPAN
lang=EN-US>StatusBar</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件和</SPAN><SPAN
lang=EN-US>1</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个</SPAN><SPAN
lang=EN-US>Memo</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件,它们的作用如下所示:</SPAN></P>
<P class=MsoNormal
style="MARGIN-LEFT: 42pt; TEXT-INDENT: -21pt; tab-stops: list 42.0pt; mso-list: l0 level1 lfo1"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN lang=EN-US>Panel</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件:用做三个加速按钮</SPAN><SPAN
lang=EN-US>(SpeedButton</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件</SPAN><SPAN
lang=EN-US>)</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的容器,使得三个加速按钮组成一个集合;</SPAN></P>
<P class=MsoNormal
style="MARGIN-LEFT: 42pt; TEXT-INDENT: -21pt; tab-stops: list 42.0pt; mso-list: l0 level1 lfo1"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN lang=EN-US>SpeedButton</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件:为状态条显示提示文本提供信息;</SPAN></P>
<P class=MsoNormal
style="MARGIN-LEFT: 42pt; TEXT-INDENT: -21pt; tab-stops: list 42.0pt; mso-list: l0 level1 lfo1"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN lang=EN-US>StatusBar</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件:显示应用程序中的提示文本和当前系统的时间和日期;</SPAN></P>
<P class=MsoNormal
style="MARGIN-LEFT: 42pt; TEXT-INDENT: -21pt; tab-stops: list 42.0pt; mso-list: l0 level1 lfo1"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN lang=EN-US>Memo</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件:作用与</SPAN><SPAN
lang=EN-US>SpeedButton</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件相同。</SPAN></P>
<H4><SPAN lang=EN-US>2</SPAN><SPAN
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.创建一个新的过程</SPAN></H4>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">由于在本程序中要在状态条中显示应用程序中各个组件的提示信息,但是在系统并没有提供现成的过程,所以在程序的设计过程中我们要自己创建一个新的过程,在键盘上按下功能键</SPAN><SPAN
lang=EN-US>Alt+F12</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,在屏幕上就会弹出一个如图</SPAN><SPAN
lang=EN-US>2-27</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示的对话框。</SPAN></P>
<P class=a><SPAN lang=EN-US><IMG height=210
src="C++ Builder 程序设计实用教程 - 2_6 状态条组件 - 张晋 - 17xie.files/8fc16d5cba.jpg"
width=303 v:shapes="_x0000_i1027"></SPAN></P>
<P class=MsoCaption><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN
lang=EN-US>2-27<SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">弹出的代码窗口</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">把光标移动到声明编辑代码中,并且添加如下所示的代码:</SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US>#ifndef StatusBarH</SPAN></P>
<P class=a1><SPAN lang=EN-US>#define StatusBarH</SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <Classes.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <Controls.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <StdCtrls.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <Forms.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <Buttons.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <ComCtrls.hpp></SPAN></P>
<P class=a1><SPAN lang=EN-US>#include <ExtCtrls.hpp></SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US>class TForm1 : public TForm</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN lang=EN-US>__published:<SPAN
style="mso-tab-count: 1"> </SPAN>//
IDE-managed Components</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TPanel *Panel1;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TSpeedButton *SpeedButton1;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TSpeedButton *SpeedButton2;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TSpeedButton *SpeedButton3;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN
style="mso-spacerun: yes"> </SPAN>TSpeedButton *SpeedButton4;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TMemo *Memo1;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TStatusBar *StatusBar1;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TStatusBar *StatusBar2;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>TStatusBar *StatusBar3;</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes"> </SPAN>void
__fastcall FormCreate(TObject *Sender);</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes"> </SPAN>void
__fastcall DisplayHint(TObject *Sender);</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">过程声明</SPAN></P>
<P class=a1><SPAN lang=EN-US>private:<SPAN
style="mso-tab-count: 1"> </SPAN>// User
declarations</SPAN></P>
<P class=a1><SPAN lang=EN-US>public:<SPAN
style="mso-tab-count: 1"> </SPAN>//
User declarations</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes">
</SPAN>__fastcall TForm1(TComponent* Owner);</SPAN></P>
<P class=a1><SPAN lang=EN-US>};</SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US>extern PACKAGE TForm1 *Form1;</SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US>#endif</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在声明段中</SPAN><SPAN
lang=EN-US>void __fastcall DisplayHint(TObject *Sender);</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">即为刚刚声明的新过程。</SPAN></P>
<H4><SPAN lang=EN-US>3</SPAN><SPAN
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.为新建过程添加代码</SPAN></H4>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在前一步中我们声明了一个新的过程,接下来就应该为这个新建的过程添加程序处理代码,在代码窗口的程序段中自己用键盘输入如下的过程处理代码:</SPAN></P>
<P class=a1><SPAN lang=EN-US>void __fastcall TForm1::DisplayHint(TObject
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>StatusBar1->SimpleText = GetLongHint(Application->Hint);</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">显示提示文本</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>Form1->StatusBar2->SimpleText=TimeToStr(Time());</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">显示当前的时间</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>Form1->StatusBar3->SimpleText=DateToStr(Date());</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN>//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">显示当前的日期</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN
lang=EN-US>//---------------------------------------------------------------------------</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值得注意的是,以上这段代码的框架无法通过</SPAN><SPAN
lang=EN-US>CBuilder 5</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成,只能够自己输入,第一条语句:</SPAN><SPAN
lang=EN-US>StatusBar1->SimpleText =
GetLongHint(Application->Hint);</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用于在第一个状态条中显示普通的提示文本,而通过第三条和第五条语句则可以在相应的状态条中显示系统当前的时间和日期。</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以上程序段的难点就在于,通过</SPAN><SPAN
lang=EN-US>Time</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -