亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch09.htm

?? 24小時學會vc++
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>		<TITLE>Teach Yourself Visual C++&#174; 5 in 24 Hours -- Hour 9 -- The Document/View Architecture</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself Visual C++&#174; 5 in 24 Hours</FONT></H1></CENTER><CENTER><P><A HREF="../ch08/ch08.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch10/ch10.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1><FONT COLOR="#000077">- Hour 9 -<BR>The Document/View Architecture</FONT></H1></CENTER><P>The main topic for this hour is Document/View, the architecture used by programswritten using AppWizard and the MFC class library. In this hour, you will learn<UL>	<LI>The support offered for Document/View by the MFC class library and tools such	as AppWizard and ClassWizard<BR>	<BR>		<LI>The MFC classes used to implement Document/View<BR>	<BR>		<LI>Using pointers and references and the role they play in Document/View</UL><P>Also in this hour you will build DVTest, a sample program that will help illustratehow documents and views interact with each other in an MFC program.<H2><FONT COLOR="#000077"><B>Visual C++ Support for Document/View</B></FONT></H2><P>MFC and AppWizard use the Document/View architecture to organize programs writtenfor Windows. Document/View separates the program into four main classes:<UL>	<LI>A document class derived from <TT>CDocument</TT><BR>	<BR>		<LI>A view class derived from <TT>CView</TT><BR>	<BR>		<LI>A frame class derived from <TT>CFrameWnd</TT><BR>	<BR>		<LI>An application class derived from <TT>CWinApp</TT></UL><P>Each of these classes has a specific role to play in an MFC Document/View application.The document class is responsible for the program's data. The view class handlesinteraction between the document and the user. The frame class contains the viewand other user interface elements, such as the menu and toolbars. The applicationclass is responsible for actually starting the program and handling some general-purposeinteraction with Windows. Figure 9.1 shows the four main parts of a Document/Viewprogram.</P><P><A NAME="01"></A><A HREF="01.htm"><B>Figure 9.1.</B></A> <I><BR>The Document/View architecture.</I></P><P>Although the name &quot;Document/View&quot; might seem to limit you to only word-processingapplications, the architecture can be used in a wide variety of program types. Thereis no limitation as to the data managed by <TT>CDocument</TT>; it can be a word processingfile, a spreadsheet, or a server at the other end of a network connection providinginformation to your program. Likewise, there are many types of views. A view canbe a simple window, as used in the simple SDI applications presented so far, or itcan be derived from <TT>CFormView</TT>, with all the capabilities of a dialog box.You will learn about form views in Hour 23, &quot;Advanced Views.&quot;<H3><FONT COLOR="#000077"><B>SDI and MDI Applications</B></FONT></H3><P>There are two basic types of Document/View programs:<UL>	<LI>SDI, or Single Document Interface<BR>	<BR>		<LI>MDI, or Multiple Document Interface</UL><P>An SDI program supports a single type of document and almost always supports onlya single view. Only one document can be open at a time. An SDI application focuseson a particular task and usually is fairly straightforward.</P><P>Several different types of documents can be used in an MDI program, with eachdocument having one or more views. Several documents can be open at a time, and theopen document often uses a customized toolbar and menus that fit the needs of thatparticular document.<H3><FONT COLOR="#000077"><B>Why Use Document/View?</B></FONT></H3><P>The first reason to use Document/View is that it provides a large amount of applicationcode for free. You should always try to write as little new source code as possible,and that means using MFC classes and letting AppWizard and ClassWizard do a lot ofthe work for you. A large amount of the code that is written for you in the formof MFC classes and AppWizard code uses the Document/View architecture.</P><P>The Document/View architecture defines several main categories for classes usedin a Windows program. Document/View provides a flexible framework that you can useto create almost any type of Windows program. One of the big advantages of the Document/Viewarchitecture is that it divides the work in a Windows program into well-defined categories.Most classes fall into one of the four main class categories:<UL>	<LI>Controls and other user-interface elements related to a specific view<BR>	<BR>		<LI>Data and data-handling classes, which belong to a document<BR>	<BR>		<LI>Work that involves handling the toolbar, status bar, and menus, usually belonging	to the frame class<BR>	<BR>		<LI>Interaction between the application and Windows occurring in the class derived	from <TT>CWinApp</TT></UL><P>Dividing work done by your program helps you manage the design of your programmore effectively. Extending programs that use the Document/View architecture is fairlysimple because the four main Document/View classes communicate with each other throughwell-defined interfaces. For example, to change an SDI program to an MDI program,you must write little new code. Changing the user interface for a Document/View programimpacts only the view class or classes; no changes are needed for the document, frame,or application classes.<H3><FONT COLOR="#000077"><B>Using AppWizard</B></FONT></H3><P>Use AppWizard to create SDI and MDI applications. In earlier chapters, you useAppWizard to create the SDI programs used as examples. Although doing so is morecomplicated, you can use AppWizard to create an MDI application almost as easilyas an SDI.</P><P>The basic difference between an SDI application and an MDI application is thatan MDI application must manage multiple documents and, usually, multiple views. TheSDI application uses only a single document, and normally only a single view.</P><P>Both SDI and MDI applications use an object called a document template to createa relationship between a view, a document, and a frame class, as well as an identifierused for the program's menu, icon, and other resources. You use the <TT>CSingleDocTemplate</TT>class for SDI applications and the <TT>CMultiDocTemplate</TT> class for MDI applications.These two classes share a common base class, <TT>CDocTemplate</TT>. Listing 9.1 isan example of a document template used for an SDI program.<H4><FONT COLOR="#000077">TYPE: Listing 9.1. How AppWizard uses a document templatein an SDI application.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>CSingleDocTemplate* pDocTemplate;</TT><TT>pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME,</TT><TT>                                       RUNTIME_CLASS(CTestDoc),</TT><TT>                                       RUNTIME_CLASS(CMainFrame),</TT><TT>                                       RUNTIME_CLASS(CTestView));</TT><TT>AddDocTemplate(pDocTemplate);</TT></FONT></PRE><P>Two types of frame windows exist in an MDI program: the main frame, which encompassesthe entire client area, and the child frame, which contains each MDI child window.The different windows used in an MDI program are shown in Figure 9.2.</P><P><A NAME="02"></A><A HREF="02.htm"><B>Figure 9.2.</B> </A><BR><I>The windows used in a typical MDI program.</I></P><P>The C++ source code generated by Developer Studio for an MDI program is slightlydifferent than the code it generates for an SDI program. Examine this code, shownin Listing 9.2, to see some of the differences between MDI objects and SDI objects.<H4><FONT COLOR="#000077">TYPE: Listing 9.2. AppWizard code that uses a documenttemplate in an MDI application.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>CMultiDocTemplate* pDocTemplate;</TT><TT>pDocTemplate = new CMultiDocTemplate( IDR_TESTTYPE,</TT><TT>                                      RUNTIME_CLASS(CTestDoc),</TT><TT>                                      RUNTIME_CLASS(CChildFrame),</TT><TT>                                      RUNTIME_CLASS(CTestView));</TT><TT>AddDocTemplate(pDocTemplate);</TT></FONT></PRE><P><TT>CChildFrame</TT> is a class included in every MDI project created by AppWizard,and is derived from <TT>CMDIChildFrame</TT>. This class is provided to make customizingthe frame to suit your needs easy. Every MDI child window has a frame that owns theminimize, maximize, and close buttons and the frame around the view. Any customizationyou want to do to the frame is done in the <TT>CChildFrame</TT> class.<H3><FONT COLOR="#000077"><B>Using ClassWizard</B></FONT></H3><P>You have used ClassWizard in previous hours to add member variables to dialogbox classes, add new classes to a project, and handle messages sent to view windowsand dialog boxes. You also use ClassWizard to add interfaces defined as part of theDocument/View architecture. In most cases, default behavior provided by the MFC frameworkis enough for simple programs.</P><P>You will learn about the interfaces used by the document and view classes in thenext section. However, you add almost all these interfaces using ClassWizard. Let'slook at one of these interfaces, <TT>GetFirstViewPosition</TT>. A document can obtaina pointer to the first view associated with the document using this function. Normally,the framework will maintain a list of the views associated with a document, but youcan keep this list yourself by overriding this function. Because the <TT>GetFirstViewPosition</TT>function is virtual, your implementation of it is always called if available.</P><P>To add an implementation for one of the Document/View interface functions, followthese steps, which are similar to the steps used to add message-handling functions:<DL>	<DD>1. Open ClassWizard.<BR>	<BR>	2. Select the name of the class that supplies the interface to be added; in this	case, a class derived from <TT>CDocument</TT>.<BR>	<BR>	3. Select the Message Maps tab.<BR>	<BR>	4. Select the <TT>CDocument</TT>-derived class as the object ID.<BR>	<BR>	5. Select the interface function to be added from the list box.<BR>	<BR>	6. Click the Add Function button.<BR>	<BR>	7. Close ClassWizard.</DL><P>You can use ClassWizard to override all the interfaces defined for programs usingthe Document/View architecture. Interfaces such as <TT>GetFirstViewPosition</TT>are rarely overridden, except when debugging. If you provide a new version of <TT>GetFirstViewPosition</TT>,you probably should override the related function <TT>GetNextView</TT> as well.</P><P>For the remaining examples in this hour, you will create an MDI project namedDVTest. To create the DVTest example, use AppWizard to create a default MDI program.Name the program DVTest. Feel free to accept or change any of the default parametersoffered by AppWizard because they have no impact on these examples. When finished,DVTest displays a collection of names stored by the document class.<H2><FONT COLOR="#000077"><B>Pointers and References</B></FONT></H2><P>Pointers are important topics in C++ programming. A good understanding of theways in which pointers are used will help you write programs that are more flexibleand reliable. C++, and MFC in particular, relies very heavily on proper understandingand use of pointers.</P><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>pointer</I> is simplya numeric variable. This numeric variable is an <I>address</I>, or location in memorywhere the actual data resides.<I> </I>Pointers must also follow the same rules thatare applied to other variables. They must have unique names, and they must be declaredbefore they can be used.</P><P>Every object or variable that is used in an application takes up a location ormultiple locations in memory. This memory location is accessed via an address (seeFigure 9.3).</P><P><A NAME="03"></A><A HREF="03.htm"><B>Figure 9.3.</B> </A><BR><I>The text <TT>Hello</TT> stored beginning at address 1000.</I></P><P>In this figure, the text <I><TT>Hello</TT></I> is stored in memory beginning ataddress 1000. Each character takes up a unique address space in memory. Pointersprovide a method for holding and getting to these addresses in memory. Pointers makemanipulating the data easier because they hold the address of another variable ordata location.<BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>Pointers give flexibility	to C++ programs and enable the programs to grow dynamically. By using a pointer to	a block of memory that is allocated at runtime, a program can be much more flexible	than one that allocates all its memory at once. <HR></BLOCKQUOTE><P>A pointer is also easier to store than a large structure or class object. Becausea pointer just stores an address, it can easily be passed to a function. However,if an object is passed to a function, the object must be constructed, copied, anddestroyed, which can be costly for large objects.<H3><FONT COLOR="#000077"><B>How Are Pointers Used?</B></FONT></H3><P>When using pointers and memory addresses, it is often useful to know the amountof memory required for each object pointed to. If you must know the amount of storagerequired for a particular object or variable, you can use the <TT>sizeof</TT> operator.You can also use <TT>sizeof</TT> to determine the amount of storage required foryour own classes and structures, as shown in Listing 9.3.<H4><FONT COLOR="#000077">TYPE: Listing 9.3. Using sizeof with class types.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>void DisplayBtnSize()</TT><TT>{</TT><TT>    int nSize = sizeof(CButton);</TT><TT>    CString strMsg;</TT><TT>    strMsg.Format(&quot;The size of CButton is %d bytes&quot;, nSize);</TT><TT>    AfxMessageBox(strMsg);</TT><TT>}</TT></FONT></PRE><H3><FONT COLOR="#000077"><B>The Indirection and Address Operators</B></FONT></H3><P>Two operators are used when working with addresses in a C++ program: the <I>address-ofoperator</I> (<TT>&amp;</TT>) and the <I>indirection operator</I> (<TT>*</TT>). Theseoperators are different from operators seen previously because they are <I>unary</I>,meaning that they work with only one operand.</P><P>The address-of operator, <TT>&amp;</TT>, returns the address of a variable orobject. This operator is associated with the object to its right, like this:</P><PRE><FONT COLOR="#0066FF"><TT>&amp;myAge;</TT></FONT></PRE><P>This line returns the address of the <TT>myAge</TT> variable.</P><P>The indirection operator, <TT>*</TT>, works like the address-of operator in reverse.It also is associated with the object to its right, and it takes an address and returnsthe object contained at that address. For example, the following line determinesthe address of the <TT>myAge</TT> variable; then it uses the indirection operatorto access the variable and give it a value of 42:</P><PRE><FONT COLOR="#0066FF"><TT>*(&amp;myAge) = 42;</TT></FONT></PRE><H3><FONT COLOR="#000077"><B>Using the Indirection Operator</B></FONT></H3><P>You can use a pointer with the indirection operator to change the value of theother variable, as shown in the console-mode program in Listing 9.4.<H4><FONT COLOR="#000077">TYPE: Listing 9.4. Using a pointer variable with the indirectionoperator.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#include &lt;iostream&gt;</TT><TT>using namespace std;</TT><TT>int main()</TT><TT>{</TT><TT>    int  nVar;</TT><TT>    int* pVar;</TT><TT>    // Store a value in nVar, and display it. Also</TT><TT>    // display nVar's address.</TT><TT>    nVar = 5;</TT><TT>    cout &lt;&lt; &quot;nVar's value is &quot; &lt;&lt; nVar &lt;&lt; &quot;.&quot; &lt;&lt; endl;</TT><TT>    cout &lt;&lt; &quot;nVar's address is &quot; &lt;&lt; &amp;nVar &lt;&lt; &quot;.&quot; &lt;&lt; endl;</TT><TT>    // Store the address of nVar in pointer pVar. Display</TT><TT>    // information about pVar and the address it points to.</TT><TT>    pVar = &amp;nVar;</TT><TT>    cout &lt;&lt; &quot;pVar's value is &quot; &lt;&lt; pVar &lt;&lt; &quot;.&quot; &lt;&lt; endl;</TT><TT>    cout &lt;&lt; &quot;*pVar's value is &quot; &lt;&lt; *pVar &lt;&lt; &quot;.&quot; &lt;&lt; endl;</TT><TT>    // Change the value of the variable pointed to by pVar.</TT><TT>    *pVar = 7;</TT><TT>    cout &lt;&lt; &quot;nVar's value is &quot; &lt;&lt; nVar &lt;&lt; &quot;.&quot; &lt;&lt; endl;</TT>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品麻豆99久久久久久| 欧美亚洲尤物久久| 国产精品一区二区果冻传媒| 国产在线播精品第三| 粉嫩aⅴ一区二区三区四区| 色婷婷综合在线| 91精品国产一区二区三区香蕉 | 亚洲福利一二三区| 美腿丝袜亚洲三区| www.性欧美| 欧美日韩你懂的| 国产日韩欧美综合在线| 亚洲精品综合在线| 美腿丝袜亚洲综合| 日本乱人伦一区| 亚洲精品一区二区三区影院| 亚洲情趣在线观看| 一区二区三区在线视频免费观看| 蜜臀av性久久久久蜜臀aⅴ流畅 | 日日摸夜夜添夜夜添亚洲女人| 激情综合五月天| 色美美综合视频| 2020日本不卡一区二区视频| 亚洲成人自拍偷拍| 盗摄精品av一区二区三区| 欧美日韩国产乱码电影| 国产亚洲综合在线| 日一区二区三区| 99国产精品久久久久久久久久久| 日韩精品专区在线影院重磅| 亚洲精品国产无天堂网2021 | ㊣最新国产の精品bt伙计久久| 日韩成人免费看| 91黄色免费观看| 中文字幕av不卡| 韩国理伦片一区二区三区在线播放| 在线亚洲一区二区| 亚洲欧洲国产日本综合| 国产精品一区二区果冻传媒| 日韩精品中文字幕一区二区三区| 亚洲一二三区在线观看| www..com久久爱| 久久久噜噜噜久久人人看 | 26uuu国产日韩综合| 亚洲va欧美va人人爽| 99精品久久免费看蜜臀剧情介绍| 欧美电影免费观看高清完整版在线观看 | 日韩一级在线观看| 亚洲欧美在线视频| 麻豆成人久久精品二区三区红| 欧美日韩的一区二区| 国产欧美日韩中文久久| 国产丶欧美丶日本不卡视频| 26uuu成人网一区二区三区| 麻豆精品视频在线观看免费| 欧美日韩在线播| 亚洲精品第一国产综合野| 激情综合网激情| 精品国产露脸精彩对白| 麻豆精品一区二区三区| 日韩视频一区二区在线观看| 蜜臀va亚洲va欧美va天堂| 欧美肥妇bbw| 一区在线观看免费| 国产精品一二三| 国产精品视频一区二区三区不卡| 国产精品一区二区三区四区 | 一区二区三区欧美日| 国产成人综合网| 国产精品国产成人国产三级| 91麻豆成人久久精品二区三区| 成人免费在线视频观看| 一区二区三区四区av| 日韩欧美一区二区免费| 日产国产欧美视频一区精品| 51午夜精品国产| 亚洲人成网站影音先锋播放| 在线精品视频一区二区| 丝袜诱惑制服诱惑色一区在线观看 | 日本大香伊一区二区三区| 国产精品不卡视频| 欧美亚洲国产怡红院影院| 日本va欧美va精品发布| 国产香蕉久久精品综合网| 国产麻豆成人传媒免费观看| 久久蜜桃香蕉精品一区二区三区| 成人免费高清视频| 国产精品久线在线观看| 不卡av在线免费观看| 亚洲专区一二三| 2023国产精品| 欧美日精品一区视频| 国产一区二区三区香蕉 | 国产精品大尺度| 欧美日韩国产免费一区二区| 国产米奇在线777精品观看| 一区二区三区欧美日韩| 日韩欧美国产高清| 国产麻豆欧美日韩一区| 自拍偷拍亚洲激情| 欧美日韩美女一区二区| 成人一区二区视频| 日本视频一区二区三区| 中文字幕一区二区不卡| 日韩午夜激情av| jlzzjlzz欧美大全| 精品在线你懂的| 亚洲与欧洲av电影| 中文字幕高清不卡| 日韩免费视频线观看| 波多野结衣中文一区| 激情综合色综合久久综合| 国产精品青草综合久久久久99| 3atv一区二区三区| 免费看精品久久片| 一级特黄大欧美久久久| 日韩欧美一区中文| 欧美日韩在线精品一区二区三区激情| 成人精品视频.| 全部av―极品视觉盛宴亚洲| 椎名由奈av一区二区三区| 国产欧美日韩亚州综合| 精品少妇一区二区三区视频免付费| 在线观看视频一区二区| 不卡在线视频中文字幕| 精品国产乱码久久久久久1区2区| 国产精品一区在线| 亚欧色一区w666天堂| 国产精品理论片在线观看| 精品久久久久久综合日本欧美| 欧美综合亚洲图片综合区| 成人精品一区二区三区中文字幕| 蜜臀精品一区二区三区在线观看 | 亚洲黄色性网站| 中文字幕一区二区不卡| 国产精品麻豆一区二区| 久久久国际精品| 久久精品一级爱片| 精品福利一区二区三区免费视频| 福利91精品一区二区三区| 国产在线不卡一卡二卡三卡四卡| 欧美韩国一区二区| 国产精品视频观看| 欧美韩日一区二区三区| 中文字幕一区二区三区视频| 国产精品色噜噜| 综合久久久久久久| 亚洲美女屁股眼交| 一区二区三区在线观看网站| 一区二区三区日韩在线观看| 91精品欧美久久久久久动漫| 美国毛片一区二区三区| 秋霞成人午夜伦在线观看| 国产成人精品免费在线| 99精品视频在线免费观看| 欧美日本一区二区| 日韩欧美国产综合一区| 国产精品国产馆在线真实露脸 | 欧美va亚洲va国产综合| 欧美日韩国产大片| 国产日韩三级在线| 国产精品毛片高清在线完整版| 亚洲午夜免费视频| 精品综合久久久久久8888| 99国内精品久久| 欧美色倩网站大全免费| 国产日韩亚洲欧美综合| 午夜欧美视频在线观看| 久久99精品网久久| 91亚洲男人天堂| 日韩欧美国产精品| 一区二区三区免费在线观看| 久久精品国产澳门| 欧美理论在线播放| 国产日韩av一区| 久久97超碰国产精品超碰| 99久久婷婷国产综合精品| 精品成人a区在线观看| 亚洲精品高清在线| 97精品久久久午夜一区二区三区| 欧美精品xxxxbbbb| 亚洲一区精品在线| 国产高清成人在线| 久久综合99re88久久爱| 亚洲123区在线观看| 色噜噜偷拍精品综合在线| 欧美精品v国产精品v日韩精品 | 亚洲精品国产精华液| 国产成人免费视频网站| 欧美夫妻性生活| 午夜久久久影院| 国产成人精品三级麻豆| 国产偷国产偷亚洲高清人白洁| 国产精品进线69影院| 成人国产视频在线观看| 91麻豆精品国产91久久久久 | 一本色道亚洲精品aⅴ| 337p粉嫩大胆色噜噜噜噜亚洲| 麻豆国产精品一区二区三区| 欧美日韩国产综合一区二区|