📄 chap3_1.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>3.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="4"><b><p ALIGN="CENTER"></b></font><font color="#3973DE" FACE="Times New Roman" SIZE="4">3.1 </font><font SIZE="4" color="#3973DE">编写第一个窗口程序</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">现在我们开始编写全书的第一个程序。跟我们以前学习程序设计的方法不同(以前我们是输入完整程序,然后运行),我们首先利用</font><font FACE="Times New Roman" SIZE="3">Visual Studio</font><font SIZE="3">的可视化编程工具</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">生成框架程序,再往里边填写代码。这是一种“填空式”的编程方法:首先生成框架,然后根据目标程序的要求,看哪些地方需要修改,再往里填写代码。类似其他语言,我们把第一个程序命名为</font><font FACE="Times New Roman" SIZE="3">Hello</font><font SIZE="3">。</font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">首先启动</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">:在</font><font FACE="Times New Roman" SIZE="3">File</font><font SIZE="3">菜单下选择</font><font FACE="Times New Roman" SIZE="3">New</font><font SIZE="3">,弹出</font><font FACE="Times New Roman" SIZE="3">New</font><font SIZE="3">对话框,如图</font><font FACE="Times New Roman" SIZE="3">3.1</font><font SIZE="3">所示。</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T3_1.gif" alt="T3_1.tif (367480 bytes)" WIDTH="537" HEIGHT="349"><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><font SIZE="3"><font SIZE="3">图</font></font><font FACE="Times New Roman" SIZE="3">3.1 New</font><font SIZE="3"><font SIZE="3">对话框</font></font><font FACE="Times New Roman" SIZE="3"></p>
<p></font><font SIZE="3">在对话框顶部有一排标签,用于选择要创建的文档的类型。选择</font><font FACE="Times New Roman" SIZE="3">Projects</font><font SIZE="3">标签,然后在列表中选择</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard</font><font SIZE="3">(</font><font FACE="Times New Roman" SIZE="3">exe</font><font SIZE="3">),告诉</font><font FACE="Times New Roman" SIZE="3">Visual C++</font><font SIZE="3">要使用</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">创建一个</font><font FACE="Times New Roman" SIZE="3">EXE</font><font SIZE="3">程序;在</font><font FACE="Times New Roman" SIZE="3">Project Name</font><font SIZE="3">编辑框中输入工程文件名</font><font FACE="Times New Roman" SIZE="3">Hello</font><font SIZE="3">,在</font><font FACE="Times New Roman" SIZE="3">Location</font><font SIZE="3">中指定应用程序创建的位置,缺省情况下</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">会自动在当前目录下以工程文件名为名字创建一个新目录,在该目录下存放所有该工程的文件。这里将目录设置为“</font><font FACE="Times New Roman" SIZE="3">C:\Hello</font><font SIZE="3">”,然后选择</font><font FACE="Times New Roman" SIZE="3">OK</font><font SIZE="3">按钮,此时弹出</font><font FACE="Times New Roman" SIZE="3">MFC-AppWizard-Step1</font><font SIZE="3">对话框,如图</font><font FACE="Times New Roman" SIZE="3">3.2</font><font SIZE="3">所示。</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T3_2.gif" alt="T3_2.tif (300972 bytes)" WIDTH="523" HEIGHT="399"><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><font SIZE="3"><font SIZE="3">图</font></font><font FACE="Times New Roman" SIZE="3">3.2 MFC AppWizard-Step 1</font><font SIZE="3"><font SIZE="3">对话框</font></font><font FACE="Times New Roman" SIZE="3"></p>
<p>AppWizard</font><font SIZE="3">是一个自动化程序生成工具,它通过提示用户一系列对话框,来指定将要生成的应用程序的特性,然后自动生成相应的代码。下面,我们一步一步演示如何用</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">生成</font><font FACE="Times New Roman" SIZE="3">Hello</font><font SIZE="3">程序。</font><font FACE="Times New Roman" SIZE="3"></p>
<p>1.MFC AppWizard</font><font SIZE="3">当前显示</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard-Step1</font><font SIZE="3">对话框。在这个对话框中,可以指定生成框架的类型,包括</font><font FACE="Times New Roman" SIZE="3">Single Document</font><font SIZE="3">(单文档),</font><font FACE="Times New Roman" SIZE="3">Multiple Document</font><font SIZE="3">(多文档),</font><font FACE="Times New Roman" SIZE="3">Dialog Based</font><font SIZE="3">(基于对话框)三种。还可以从下拉列表框中选择语言,指定程序资源文件使用的语言类型。选择</font><font FACE="Times New Roman" SIZE="3">Single Document</font><font SIZE="3">,此时</font><font FACE="Times New Roman" SIZE="3">AppWizard</font><font SIZE="3">将生成一个单文档的应用程序框架,也就是说,应用程序运行时是一个单窗口的界面。点击</font><font FACE="Times New Roman" SIZE="3">Next</font><font SIZE="3">按钮。</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T3_3.gif" alt="T3_3.tif (296952 bytes)" WIDTH="488" HEIGHT="371"><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><font SIZE="3"><font SIZE="3">图</font></font><font FACE="Times New Roman" SIZE="3">3.3 MFC AppWizard-Step 2 of 6</font><font SIZE="3"><font SIZE="3">对话框</font></font><font FACE="Times New Roman" SIZE="3"></p>
<p ALIGN="JUSTIFY">2.</font><font SIZE="3">此时</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard</font><font SIZE="3">显示图</font><font FACE="Times New Roman" SIZE="3">3.3</font><font SIZE="3">所示</font><font FACE="Times New Roman" SIZE="3">MFC
AppWizard-Step 2 of 6</font><font SIZE="3">对话框。该对话框用于指定数据库选项。</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard</font><font SIZE="3">支持数据库并可以生成数据库应用程序所必需的代码。选择缺省值</font><font FACE="Times New Roman" SIZE="3">None</font><font SIZE="3">,不使用数据库特性。点击</font><font FACE="Times New Roman" SIZE="3">Next</font><font SIZE="3">按钮,弹出</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard-Step3</font><font SIZE="3">对话框,如图</font><font FACE="Times New Roman" SIZE="3">3.4</font><font SIZE="3">所示。</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T3_4.gif" alt="T3_4.tif (298033 bytes)" WIDTH="485" HEIGHT="368"><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><font SIZE="3"><font SIZE="3">图</font></font><font FACE="Times New Roman" SIZE="3">3.4 MFC AppWizard-Step 3 of 6</font><font SIZE="3"><font SIZE="3">对话框</font></font><font FACE="Times New Roman" SIZE="3"></p>
<p>3.</font><font SIZE="3">在</font><font FACE="Times New Roman" SIZE="3">MFC
AppWizard-Step 3 of 6</font><font SIZE="3">对话框中,可以指定</font><font FACE="Times New Roman" SIZE="3">OLE</font><font SIZE="3">选项的复合文档类型。因为我们不用</font><font FACE="Times New Roman" SIZE="3">OLE</font><font SIZE="3">特性,所以使用缺省值</font><font FACE="Times New Roman" SIZE="3">None</font><font SIZE="3">。点击</font><font FACE="Times New Roman" SIZE="3">Next</font><font SIZE="3">按钮,进入下一个对话框。此时,屏幕显示</font><font FACE="Times New Roman" SIZE="3">MFC-AppWizard-Step 4 of 6</font><font SIZE="3">对话框,如图</font><font FACE="Times New Roman" SIZE="3">3.5</font><font SIZE="3">。</font><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><img src="T3_5.gif" alt="T3_5.tif (299042 bytes)" WIDTH="495" HEIGHT="379"><font FACE="Times New Roman" SIZE="3"></p>
<p align="center"></font><font SIZE="3"><font SIZE="3">图</font></font><font FACE="Times New Roman" SIZE="3">3.5 MFC AppWizard-Step 4 of 6</font><font SIZE="3"><font SIZE="3">对话框</font></font><font FACE="Times New Roman" SIZE="3"></p>
<p ALIGN="JUSTIFY">4.</font><font SIZE="3">第四个对话框用于指定应用程序的外观,包括是否使用工具条、状态栏,是否让文档支持打印和打印预览功能,是否使用</font><font FACE="Times New Roman" SIZE="3">3D</font><font SIZE="3">控制外观,以及是否支持在线帮助等。</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard</font><font SIZE="3">还支持</font><font FACE="Times New Roman" SIZE="3">WOSA</font><font SIZE="3">(</font><font FACE="Times New Roman" SIZE="3">Windows</font><font SIZE="3">开放系统体系结构),可以直接在基于文档的程序中加入</font><font FACE="Times New Roman" SIZE="3">MAPI</font><font SIZE="3">电子邮件发送功能和</font><font FACE="Times New Roman" SIZE="3">WinSocket</font><font SIZE="3">网络编程接口支持。另外,还可以指定文档的一些特性,包括后缀名等。有关文档</font><font FACE="Times New Roman" SIZE="3">/</font><font SIZE="3">视结构的内容在后面章节中再作详细介绍。按照图</font><font FACE="Times New Roman" SIZE="3">3.5</font><font SIZE="3">所示,设置各个选项,它支持工具条、状态栏,使用</font><font FACE="Times New Roman" SIZE="3">3D</font><font SIZE="3">外观的控制。点击</font><font FACE="Times New Roman" SIZE="3">Next</font><font SIZE="3">按钮,弹出</font><font FACE="Times New Roman" SIZE="3">MFC AppWizard 5 of 6</font><font SIZE="3">对话框,如图</font><font FACE="Times New Roman" SIZE="3">3.6</font><font SIZE="3">所示。</font><font FACE="Times New Roman" SIZE="3"></p>
<p ALIGN="center"><img src="T3_6.gif" alt="T3_6.tif (296952 bytes)" WIDTH="490" HEIGHT="372"></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -