📄 chap5_1.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>5.1对话框和控件的基本概念</title>
</head>
<body link="#3973DE" alink="#3973DE">
<font SIZE="5"><b><div align="center"><center>
<table border="0" width="615" cellspacing="0" cellpadding="0">
<tr>
</b><td><div align="center"><center><table border="0" width="615" cellpadding="0" cellspacing="0" height="20">
<tr>
<td width="377" bgcolor="#15397D" height="20"></td>
<td width="238" bgcolor="#000000" height="20"><p align="right"></font><span style="text-decoration: none"><a href="../../index.htm"><font color="#FFFFFF">电脑报Visual
C++网络教程</font></a></span></td>
</tr>
</table>
</center></div><font FACE="Times New Roman" SIZE="3"><b><p ALIGN="CENTER"></b></font><font FACE="Times New Roman" size="4" color="#3973DE">5.1</font><font size="4" color="#3973DE">对话框和控件的基本概念</font><font FACE="Times New Roman" size="4"></p>
<p ALIGN="CENTER"></font><b><font SIZE="3"> </font><font FACE="Times New Roman" SIZE="3"></p>
<p></font></b><font color="#3973DE" FACE="Times New Roman" SIZE="3">5.1.1</font><font SIZE="3" color="#3973DE">对话框的基本概念</font><font SIZE="3"></p>
<p ALIGN="JUSTIFY"><b> </b> 对话框</font><font FACE="Times New Roman" SIZE="3">(Dialog)</font><font SIZE="3">实际上是一个窗口.在</font><font FACE="Times New Roman" SIZE="3">MFC</font><font SIZE="3">中,对话框的功能被封装在了</font><font FACE="Times New Roman" SIZE="3">CDialog</font><font SIZE="3">类中,</font><font FACE="Times New Roman" SIZE="3">CDialog</font><font SIZE="3">类是</font><font FACE="Times New Roman" SIZE="3">CWnd</font><font SIZE="3">类的派生类.</p>
<p> 对话框分为模态对话框和非模态对话框两种.大部分读者都会有这样的经历,当你通过</font><font FACE="Times New Roman" SIZE="3">File-Open</font><font SIZE="3">命令打开一个文件对话框后,再用鼠标去选择菜单将只会发出嘟嘟声,这是因为文件对话框是一个模态对话框.模态对话框垄断了用户的输入,当一个模态对话框打开时,用户只能与该对话框进行交互,而其它用户界面对象收不到输入信息.我们平时所遇到的大部分对话框都是模态对话框。非模态对话框的典型例子是</font><font FACE="Times New Roman" SIZE="3">Windows95</font><font SIZE="3">提供的写字板程序中的搜索对话框,搜索对话框不垄断用户的输入,打开搜索对话框后,仍可与其它用户界面对象进行交互,用户可以一边搜索,一边修改文章,这样就大大方便了使用.</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">本节主要介绍模态对话框,在第四节将介绍非模态对话框.</p>
<p> 从</font><font FACE="Times New Roman" SIZE="3">MFC</font><font SIZE="3">编程的角度来看,一个对话框由两部分组成:</p>
<blockquote>
<blockquote>
<p>对话框模板资源.对话框模板用于指定对话框的控件及其分布,</font><font FACE="Times New Roman" SIZE="3">Windows</font><font SIZE="3">根据对话框模板来创建并显示对话框.</p>
<p>对话框类.对话框类用来实现对话框的功能,由于对话框行使的功能各不相同,因此一般需要从</font><font FACE="Times New Roman" SIZE="3">CDialog</font><font SIZE="3">类派生一个新类,以完成特定的功能.</p>
</blockquote>
</blockquote>
<p> 相应地,对话框的设计包括对话框模板的设计和对话框类的设计两个主要方面.</font><font FACE="Times New Roman" SIZE="3"></p>
<p ALIGN="left"></font><font SIZE="3">
与对话框有关的消息主要包括</font><font FACE="Times New Roman" SIZE="3">WM_INITDIALOG</font><font SIZE="3">消息和控件通知消息。在对话框创建时,会收到</font><font FACE="Times New Roman" SIZE="3">WM_INITDIALOG</font><font SIZE="3">消息,对话框对该消息的处理函数是</font><font FACE="Times New Roman" SIZE="3">OnInitDialog</font><font SIZE="3"> 。</font><font FACE="Times New Roman" SIZE="3"><b></p>
<p ALIGN="left"></b> OnInitDialog</font><font SIZE="3">的主要用处是初始化对话框。对话框的控件会向对话框发送控件通知消息,以表明控件的状态发生了变化。</font><b><font FACE="Times New Roman" SIZE="3"></p>
<p></font></b><font color="#3973DE" FACE="Times New Roman" SIZE="3">5.1.2</font><font SIZE="3" color="#3973DE">控件的基本概念</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T5_1.gif" alt="T5_1.tif (317964 bytes)" WIDTH="565" HEIGHT="378"><font SIZE="3"></p>
<p align="center"></font><font size="2">图<font FACE="Times New Roman">5.1</font>对话框中的控件</p>
<p ALIGN="JUSTIFY"></font><font SIZE="3"> 控件</font><font FACE="Times New Roman" SIZE="3">(Control)</font><font SIZE="3">是独立的小部件,在对话框与用户的交互过程中,控件担任着主要角色.控件的种类较多,图</font><font FACE="Times New Roman" SIZE="3">5.1</font><font SIZE="3">显示了对话框中的一些基本的控件.</font><font FACE="Times New Roman" SIZE="3">MFC</font><font SIZE="3">的控件类封装了控件的功能,表</font><font FACE="Times New Roman" SIZE="3">5.1</font><font SIZE="3">介绍了一些常用的控件及其对应的控件类.<b></p>
<p ALIGN="CENTER">表</font><font FACE="Times New Roman" SIZE="3">5.1</font></b></p>
<table BORDER="1" CELLSPACING="1" CELLPADDING="1" WIDTH="579">
<tr>
<td WIDTH="27%"><font SIZE="3"><b>控件</b></font></td>
<td WIDTH="55%"><font SIZE="3"><b>功能</b></font></td>
<td WIDTH="18%"><b><font SIZE="3">对应控件类</font></b></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">静态正文</font><font FACE="Times New Roman" SIZE="3">(Static
Text)</font></td>
<td WIDTH="55%"><font SIZE="3">显示正文,一般不能接受输入信息。</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CStatic</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">图片</font><font FACE="Times New Roman" SIZE="3">(Picture)</font></td>
<td WIDTH="55%"><font SIZE="3">显式位图、图标、方框和图元文件,一般不能接受输入信息.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CStatic</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">编辑框</font><font FACE="Times New Roman" SIZE="3">(Edit
Box)</font></td>
<td WIDTH="55%"><font SIZE="3">输入并编辑正文,支持单行和多行编辑.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CEdit</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">命令按钮</font><font FACE="Times New Roman" SIZE="3">(Pushbutton)</font></td>
<td WIDTH="55%"><font SIZE="3">响应用户的输入,触发相应的事件.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CButton</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">检查框</font><font FACE="Times New Roman" SIZE="3">(Check
Box)</font></td>
<td WIDTH="55%"><font SIZE="3">用作选择标记,可以有选中、不选中和不确定三种状态。</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CButton</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">单选按钮</font><font FACE="Times New Roman" SIZE="3">(Radio
Button)</font></td>
<td WIDTH="55%"><font SIZE="3">用来从两个或多个选项中选中一项.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CButton</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">组框</font><font FACE="Times New Roman" SIZE="3">(Group
Box)</font></td>
<td WIDTH="55%"><font SIZE="3">显示正文和方框,主要用来将相关的一些控件聚成一组.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CButton</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">列表框</font><font FACE="Times New Roman" SIZE="3">(List
Box)</font></td>
<td WIDTH="55%"><font SIZE="3">显示一个列表,用户可以从该列表中选择一项或多项.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CListBox</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">组合框</font><font FACE="Times New Roman" SIZE="3">(Combo
Box)</font></td>
<td WIDTH="55%"><font SIZE="3">是一个编辑框和一个列表框的组合.分为简易式、下拉式和下拉列表式.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CComboBox</font></td>
</tr>
<tr>
<td WIDTH="27%"><font SIZE="3">滚动条</font><font FACE="Times New Roman" SIZE="3">(Scroll
Bar)</font></td>
<td WIDTH="55%"><font SIZE="3">主要用来从一个预定义范围值中迅速而有效地选取一个整数值.</font></td>
<td WIDTH="18%"><font FACE="Times New Roman" SIZE="3">CScrollBar</font></td>
</tr>
</table>
<font SIZE="3"><p> 控件实际上都是窗口,所有的控件类都是</font><font FACE="Times New Roman" SIZE="3">CWnd</font><font SIZE="3">类的派生类.控件通常是作为对话框的子窗口而创建的,控件也可以出现在视窗口,工具条和状态条中.</font><font FACE="Times New Roman" SIZE="3"><b></p>
</b></font><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="615">
<tr>
<td><a href="chap5.htm">上一页</a></td>
<td><p align="right"><a href="chap5_2.htm">下一页</a></td>
</tr>
</table>
</center></div><font SIZE="5"><hr noshade color="#3973DE" size="1">
<p align="center"></font><font size="2" color="#000000">本教程由<a href="http://vcdynasty.yeah.net">Visual C++王朝(Where programmers come together)</a>协助制作<br>
未经许可,请勿以任何形式复制</font></td>
<b>
</tr>
</table>
</center></div>
<p ALIGN="CENTER"></b><font SIZE="5"> </font><font FACE="Times New Roman" SIZE="5"></p>
</font><font FACE="Times New Roman" SIZE="3">
<p></font><b><font SIZE="3"> </font><font FACE="Times New Roman" SIZE="3"></p>
</font></b>
<p><font SIZE="3"> </font><font FACE="Times New Roman" SIZE="3"></p>
<p></font> </p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -