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

📄 example19-1.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
📖 第 1 页 / 共 4 页
字号:
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:225pt;
 height:138.75pt'>
 <v:imagedata src="../../../../DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
<img src="exampl10.jpg" v:shapes="_x0000_i1025" width="228" height="133"></span></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">图</font>19-6 
<font LANG="ZH-CN">选择数据源</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<font LANG="ZH-CN">图</font>19-7 <font LANG="ZH-CN">选择表</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">打开工作区的类视图,如图</font>19-8<font LANG="ZH-CN">所示,可以发现</font>AppWizard<font LANG="ZH-CN">自动创建了一个记录集类</font>CStudentSet<font LANG="ZH-CN">和一个记录视图类</font>CStudentView<font LANG="ZH-CN">,这两个类分别是</font>CRecordset<font LANG="ZH-CN">和</font>CRecordView<font LANG="ZH-CN">的派生类。</font>AppWizard<font LANG="ZH-CN">也为</font>CStudentSet<font LANG="ZH-CN">类自动创建了域数据成员</font>m_Address<font LANG="ZH-CN">、</font>m_Aage<font LANG="ZH-CN">、</font>m_ClassID<font LANG="ZH-CN">、</font>m_Name<font LANG="ZH-CN">、</font>m_StudentID<font LANG="ZH-CN">,分别对应表中的各个字段。</font></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
 o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
 stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:199.5pt;
 height:221.25pt'>
 <v:imagedata src="../../../../DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
<img src="exampl10.jpg" v:shapes="_x0000_i1025" width="228" height="133"></span>  </font><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
 o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
 stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:152.25pt;
 height:220.5pt'>
 <v:imagedata src="../../../../DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
<img src="exampl10.jpg" v:shapes="_x0000_i1025" width="228" height="133"></span></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">图</font>19-8 
<font LANG="ZH-CN">类视图&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</font> <font LANG="ZH-CN">图</font>19-9 <font LANG="ZH-CN">资源视图</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">③</font> 
<font LANG="ZH-CN">添加控件并与记录集的域数据成员连接起来</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">打开工作区的资源视图,找到一个</font>ID<font LANG="ZH-CN">为</font>IDD_STUDENT_FORM<font LANG="ZH-CN">的对话框模板,如图</font>19-9<font LANG="ZH-CN">所示,该模板将被记录视图用来显示表单。清除该模板中的所有控件,然后按图</font>19-2<font LANG="ZH-CN">的式样放置控件。</font></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
 o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
 stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:306pt;
 height:200.25pt'>
 <v:imagedata src="../../../../DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
<img src="exampl10.jpg" v:shapes="_x0000_i1025" width="228" height="133"></span></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">图</font>19-10 
<font LANG="ZH-CN">将控件和域数据成员连接</font></font></p>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">接下来的任务是用</font>ClassWizard<font LANG="ZH-CN">把表单中的控件与记录集的域数据成员连接起来,以实现控件与当前记录的</font>DDX<font LANG="ZH-CN">数据交换。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">进入</font>ClassWizard<font LANG="ZH-CN">,选择“</font>Member 
Variables<font LANG="ZH-CN">”页并且选择“</font>CStudentView<font LANG="ZH-CN">”类。在变量列表中双击“</font>IDC_ADDRESS<font LANG="ZH-CN">”项,则会显示“</font>Add 
Member Variable<font LANG="ZH-CN">”对话框。注意该对话框的“</font>Member 
variable name<font LANG="ZH-CN">”栏显示的是一个组合框,而不是平常看到的编辑框。如图</font>19-10<font LANG="ZH-CN">所示,在组合框的列表中选择“</font>m_pSet-&gt;m_Address<font LANG="ZH-CN">”。按“</font>OK<font LANG="ZH-CN">”按钮确认。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">下面我们看类</font>CStudentView<font LANG="ZH-CN">的定义:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">class 
    CStudentView : public CRecordView</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">……</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//{{AFX_DATA(CStudentView)</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">enum 
    { IDD = IDD_STUDENT_FORM };</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">CStudentSet* 
    m_pSet; //<font LANG="ZH-CN">定义变量</font>m_pSet</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//}}AFX_DATA</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">// 
    Attributes</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">public:</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CStudentDoc* 
    GetDocument();</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">……</font></p>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">};</font></p>
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">可见</font>m_pSet<font LANG="ZH-CN">是</font>CStudentView<font LANG="ZH-CN">类的成员,它指向一个</font>CStudentSet<font LANG="ZH-CN">对象。用</font>ClassWizard<font LANG="ZH-CN">可以把控件与象记录集这样的“外部数据”连接起来,这是</font>ClassWizard<font LANG="ZH-CN">在数据库编程方面的一个特殊应用。</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">④</font> 
<font LANG="ZH-CN">处理添加新记录、删除记录、修改记录和查找等消息</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">如图</font>19-2<font LANG="ZH-CN">所示,四个按钮的标题、</font>ID<font LANG="ZH-CN">和单击消息处理函数见表</font>19-2<font LANG="ZH-CN">。</font></font></p>
<p ALIGN="center" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
 o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
 stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>

⌨️ 快捷键说明

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