友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!
第三电子书 返回本书目录 加入书签 我的书架 我的书签 TXT全本下载 『收藏到我的浏览器』

深入浅出MFC第2版(PDF格式)-第52部分

快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部! 如果本书没有阅读完,想下次继续接着阅读,可使用上方 "收藏到我的浏览器" 功能 和 "加入书签" 功能!




      很快为你产生一个骨干程序。这是一个完整的,不需增减任何一行码就可编译执行的程 



      式,虽然它什么大事儿都没做,却保证令你印象深刻。外观(使用者接口)十分华丽, 



      Win32 程序员穷数星期之心力也不见得做得出这样漂亮丰富的接口来。 



                                                                 257 


…………………………………………………………Page 320……………………………………………………………

              第篇    欲善工事先利其器 



           东圈西点完成 MFC 程序骨干 



              选按【File/New】,并在【New】对话框中选择【Project】附页。然后再在其中选择MFC Application 



               (exe),于是准备进入AppWizard 建立〃Scribble〃 project。右边的磁盘目录和project 名称 



               亦需填妥。 



258 


…………………………………………………………Page 321……………………………………………………………

                                       第4章    Visual C++  整合性軟體開發環境 



MFC AppWizard 步骤一,选择SDI 或MDI 或Dialog…based 程序风格。预设情况是MDI。 



MFC AppWizard 步骤二,选择是否需要数据库支持。预设情况是None。 



                                                                           259 


…………………………………………………………Page 322……………………………………………………………

               第篇    欲善工事先利其器 



                MFC AppWizard 步骤三,选择是否需要pound document 和ActiveX 支持。预设情况下支持ActiveX 



                Controls,本例为求简化,将它关闭。 



                注意,在VC++ 4。x 版中此处为OLE Automation 和OLE controls。 



               MFC AppWizard 步骤四,选择使用者接口。预设情况下【Context Sensitive Help】未设立。 



260 


…………………………………………………………Page 323……………………………………………………………

                                       第4章    Visual C++  整合性軟體開發環境 



MFC AppWizard 步骤四的【Advanced】带出【Advanced Options】对话框: 



把上图修改为下面这个样子。这些修改对程序代码带来的变化,将在第7章中说明。 



                                                                           261 


…………………………………………………………Page 324……………………………………………………………

               第篇    欲善工事先利其器 



               MFC AppWizard 【Advanced Options】的另一附页。其中最上面的一个核示钮【Use split window】 



               预设是关闭状态。如果要制作分裂窗口(如本书第11 章),把它打开就是了。 



               MFC AppWizard 步骤五,提供另一些选项,询问要不要为你的源代码产生一些说明文字。并询问你 



               希望使用的MFC 版本(动态联结版或静态联结版)。 



262 


…………………………………………………………Page 325……………………………………………………………

                                       第4章    Visual C++  整合性軟體開發環境 



MFC AppWizard 步骤六(最后一步),允许你更改档名或类别名称。完成后按下【Finish】 



MFC AppWizard 获得的清单(包括文件和类别): 



                                                                           263 


…………………………………………………………Page 326……………………………………………………………

               第篇    欲善工事先利其器 



               一行程序代码都还没写,就获得了这么多文件。你可以选择【Win32 Debug】或【Win32 Release】来 



               建造(building)程序,获得的二进制文件将放在不同的子目录中。 



264 


…………………………………………………………Page 327……………………………………………………………

                                      第4章    Visual C++  整合性軟體開發環境 



一行程序代码都还没写,就获得了这么多类别。 



                                                                         265 


…………………………………………………………Page 328……………………………………………………………

              第篇    欲善工事先利其器 



              一行程序代码都还没写,就获得了这么多资源。 



              一行程序代码都没写,只是点点按按,我们就获得了一个令人惊艳的程序。基本功能一应俱全(文件 



              对话框、打印机设定、Help、工具栏、状态列。。。),却什么也不能做(那是当然)。 



266 


…………………………………………………………Page 329……………………………………………………………

                                        第4章    Visual C++  整合性軟體開發環境 



 AppWizard 总是为一般的应用程序产生五个类别。我所谓的「一般程序」是指non…OLE 



 以及non…ODBC 程序。针对上述的Scribble 程序,它产生的类别列于图4…7 。 



 类别名称          基础类别         类别声明于        类别定义于 



 CScribbleApp     CWinApp        Scribble。h     Scribble。cpp 



 CMainFrame       CMDIFrameWnd   Mainfrm。h      Mainfrm。cpp 



 CChildFrame      CMDIChildWnd   Childfrm。h     Childfrm。cpp 



 CScribbleDoc     CDocument      ScribbleDoc。h  ScribbleDoc。cpp 



 CScribbleView    CView          ScribbleView。h ScribbleView。cpp 



 图4…7 Scribble Step0 ( 骨干程序)中,各个类别的相关资料。事实上Scribble 



      程序中用到了 9 个类别,不过只有上述 5 个类别需要改写 (override)。 



你最好把哪一个类别衍生自哪一个MFC 类别弄清楚,并搞懂AppWizard  的命名规则。 



大致上命名规则是这样的: 



       'C' + ProjectName + Classtype = Class Name 



所有的类别名称都由AppWizard  自动命名,如果你喜欢,也可以在AppWizard  的步骤六 



改变之。这些类别名称可以很长很长(Windows 95 与Windows NT 均支持长档名)。每 



个类别都对应一个。H       (类别声明)和一个。CPP       (类别定义)。 



AppWizard 十分周到地为我们产生了一个README。TXT ,对各个文件都有解释(图4



8) 。从激活AppWizard 到建立Scribble。exe ,如果你是熟手,机器又不慢的话,不需要 



一分钟。拿着码表算时间其实不具意义(就像计算程序行数多寡一样地不具意义),我 



要说的是它的确便利。 



                                                                            267 


…………………………………………………………Page 330……………………………………………………………

                  第篇    欲善工事先利其器 



                  ======================================================================== 

                         MICROSOFT FOUNDATION CLASS LIBRARY : Scribble 

                  ======================================================================== 



                  AppWizard has created this Scribble application for you。  This application 

                  not only demonstrates the basics of using the Microsoft Foundation classes 

                  but is also a starting point for writing your application。 



                  This file contains a summary of what you will find in each of the files that 

                  make up your Scribble application。 



                  Scribble。h 

                      This is the main header file for the application。  It includes other 

                      project specific headers (including Resource。h) and declares the 

                      CScribbleApp application class。 



                  Scribble。cpp 

                      This is the main application source file that contains the application 

                      class CScribbleApp。 



                  Scribble。rc 

                      This is a listing of all of the Microsoft Windows resources that the 

                      program uses。  It includes the icons; bitmaps; and cursors that are stored 

                      in the RES subdirectory。  This file can be directly edited in Microsoft 

                       Developer Studio。 



                  resScribble。ico 

                      This is an icon file; which is used as the application's icon。  This 

                      icon is included by the main resource file Scribble。rc。 



                  resScribble。rc2 

                      This file contains resources that are not edited by Microsoft 

                       Developer Studio。  You should place all resources not 

                       editable by the resource editor in this file。 



                  Scribble。clw 

                      This file contains information used by ClassWizard to edit existing 

                      classes or add new classes。  ClassWizard also uses this file to store 

                      information needed to create and edit message maps and dialog data 

                      maps and to create prototype member functions。 



                  ///////////////////////////////////////////////////////////////////////////// 



                  For the main frame window: 



268 


…………………………………………………………Page 331……………………………………………………………

                                          第4章    Visual C++  整合性軟體開發環境 



MainFrm。h; MainFrm。cpp 

    These files contain the frame class CMainFrame; which is derived from 

    CMDIFrameWnd and controls all MDI frame features。 



resToolbar。bmp 

    This bitmap file is used to create tiled images for the toolbar。 

    The initial toolbar and status bar are constructed in the 

    CMainFrame class。  Edit this toolbar bitmap along with the 

    array in MainFrm。cpp to add more toolbar buttons。 



///////////////////////////////////////////////////////////////////////////// 



AppWizard creates one document type and one view: 



ScribbleDoc。h; ScribbleDoc。cpp the document 

    These files contain your CScribbleDoc class。  Edit these files to 

    add your special document data and to implement file saving and loading 

    (via CScribbleDoc::Serialize)。 



ScribbleView。h; ScribbleView。cpp the view of the document 

    These files contain your CScribbleView class。 

    CScribbleView objects are used to view CScribbleDoc objects。 



resScribbleDoc。ico 

    This is an icon file; which is used as the icon for MDI child windows 

    for the CScribbleDoc class。  This icon is included by the main 

    resource file Scribble。rc。 



///////////////////////////////////////////////////////////////////////////// 

Other standard files: 



StdAfx。h; StdAfx。cpp 

    These files are used to build a prepiled header (PCH) file 

    named Scribble。pch and a prepiled types file named StdAfx。obj。 



Resource。h 

    This is the standard header file; which defines new resource IDs。 

    Microsoft Developer Studio reads and updates this file。 



///////////////////////////////////////////////////////////////////////////// 

Other notes: 



AppWizard uses 〃TODO:〃 to indicate parts of the source code you 

should add to or customize。 



                                                                                269 


…………………………………………………………Page 332……………………………………………………………

                  第篇    欲善工事先利其器 



                  If your application uses MFC in a shared DLL; and your application is 

                  in a language other than the operating system's current language; you 

                  will need to copy the corresponding localized resources MFC40XXX。DLL 

                  from the Microsoft Visual C++ CD…ROM onto the system or system32 directory; 

                  and rename it to be MFCLOC。DLL。  (〃XXX〃 stands for the language abbreviation。 

                  For example; MFC40DEU。DLL contains resources translated to German。)  If you 

                  don't do this; some of the UI elements of your application will remain in the 

                  language of the operating system。 



                  图4…8 Scribble 程序的readme。txt 档。 



                  别忘了,AppWizard 产生的是化学反应而不是物理反应,是不能
返回目录 上一页 下一页 回到顶部 0 0
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!