📄 right16-1.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 16 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">
<span style="background-color: #CCFF99">第 16 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 1 节 </span>><span style="background-color: #CCFF99">
16.1 对话框</span></p>
<hr color="#008000" size="1">
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font size="2"><font LANG="ZH-CN">在</font>MFC<font LANG="ZH-CN">环境下使用对话框有两种方法:一种是创建一个基于对话框的工程;另一种是在基于文档的工程中创建对话框资源,然后在消息驱动下显示相应的对话框。</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font size="2">1.
<font LANG="ZH-CN">创建基于对话框的工程</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)
使用AppWizard应用程序向导创建一个基于对话框的工程</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">在“MFC
AppWizard Step 1”对话框中,选择工程类型为基于对话框(Dialog
based)类型。</font></p>
<p style="line-height: 100%; text-indent: 0; margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0" align="left"><font size="2">(2)
<font LANG="ZH-CN">编辑对话框</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font size="2"><font LANG="ZH-CN">添加控件,完成对话框窗口界面设计</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font LANG="ZH-CN" size="2">(3)
创建对话框成员变量</font><font FACE="oúì?,SimHei" LANG="ZH-CN" SIZE="3"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:"Times New Roman";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:261pt;
height:171pt'>
<v:imagedata src="file:///C:/DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
o:title=""/>
</v:shape><![endif]-->
</span></p>
</font>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font lang="ZH-CN" size="2">使用ClassWizard
类向导给界面对象连接变量,见下图。</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font lang="ZH-CN" size="2" color="#008000">每个控件实际上就是一个对象,对MFC类库中的函数调用都是通过对象实现的。每一个具体的界面对象都有一个ID标识。在源程序中对这个对象操作,就是通过对与它相关联的变量进行操作来完成的。这个连接的变量就是类中的一个变量。通常变量名是以"m_"开头的。</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" SIZE="3"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA">
<img width="348" height="228" src="right11.jpg" v:shapes="_x0000_i1025"></span></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 5; margin-bottom: 0"><font LANG="ZH-CN" size="2">(4)
创建消息处理函数</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">按照上一章介绍的方法首先建立消息与消息处理函数的映射,然后编写消息处理函数。</font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font size="2">2.
<font LANG="ZH-CN">在工程中调用对话框</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0" align="left"><font size="2">(1)
<font LANG="ZH-CN">在工程中创建对话框和控件</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font lang="ZH-CN" size="2">例:对话框标识为IDD_HELP</font></p>
<p style="line-height: 100%; text-indent: 0; margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0" align="left"><font size="2">(2)
<font LANG="ZH-CN">定义对话框类</font></font><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"> </span></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font lang="ZH-CN" size="2">使用ClassWizard类向导创建一个新类</font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font lang="ZH-CN" size="2">例:对IDD_HELP对话框创建一个派生于CDialog的新类CHelpDlg,见下图</font></p>
<p style="line-height: 100%; text-indent: 0; margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0" align="left"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA">
<img width="288" height="239" src="right16.jpg" v:shapes="_x0000_i1025"></span></p>
<p style="line-height: 100%; text-indent: 0; margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0" align="left"><font size="2">(3)
<font LANG="ZH-CN">显示对话框</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" align="left"><font lang="ZH-CN" size="2">例:建立一个CHelpDlg对象,调用函数DoModal()显示对话框</font></p>
<blockquote>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">CHelpDlg
helpdlg;</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">helpdlg.DoModal();
//<font FACE="??ì?,SimSun" LANG="ZH-CN">显示对话框</font></font></p>
</blockquote>
</blockquote>
<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <span style="position: absolute; left: 31; top: 1075"><a href="right15-4.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>
<span style="position: absolute; left: 504; top: 1073"><a href="right16-2.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -