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

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

?? ch09.htm

?? 24小時學會vc++
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
set of favorite interfaces.</P><P>The interfaces defined by the Document/View architecture represent guaranteesabout how each of the MFC classes that make up an application behave with regardto each other. For example, the MFC framework always calls the <TT>CDocument::OnNewDocument</TT>function when a new document is created. The MFC framework, and other classes thatmight be part of an MFC-based program, expect the new document to be initializedafter this function has been called.</P><P>Using well-defined interfaces like <TT>CDocument::OnNewDocument</TT> to performspecific tasks enables you to modify only the functions where you must take specialaction; you can let the MFC framework handle most functions and interfaces if youwant the default behavior.</P><P>The Document/View architecture also makes it easy to separate work. For example,data belongs only to the document; a view calls the <TT>GetDocument</TT> functionto collect a document pointer and then uses member functions to collect or updatedata.<H3><FONT COLOR="#000077"><B>Creating a Data Model</B></FONT></H3><P>Each of the interfaces discussed earlier has a specific role. For the remainingexamples in this chapter, you will use the DVTest example created earlier in thishour.</P><P>Return to the DVTest example and add a <TT>CArray</TT> template object to thedocument class as a private data member. Add the source code from Listing 9.11 tothe <TT>CDVTestDoc</TT> class header, found in the <TT>DVTestDoc.h</TT> file. Addthe source code to the attributes section of the class declaration, which beginswith the <TT>// Attributes</TT> comment generated by AppWizard.<H4><FONT COLOR="#000077">TYPE: Listing 9.11. Changes to the CDVTestDoc class declaration.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>// Attributes</TT><TT>public:</TT><TT>    CString GetName( int nIndex ) const;</TT><TT>    int     AddName( const CString&amp; szName );</TT><TT>    int     GetCount() const;</TT><TT>private:</TT><TT>    CArray&lt;CString, CString&gt;    m_arNames;</TT></FONT></PRE><P>Because the <TT>CDVTestDoc</TT> class contains a <TT>CArray</TT> member variable,the template collection declarations must be included in the project. Add an <TT>#include</TT>statement at the bottom of the <TT>StdAfx.h</TT> file.</P><PRE><FONT COLOR="#0066FF"><TT>#include &quot;afxtempl.h&quot;</TT></FONT></PRE><P>The next step is to implement the functions described in the <TT>CDVTestDoc</TT>class interface. These functions provide access to the data stored in the document.Add the source code in Listing 9.12 to the <TT>DVTestDoc.cpp</TT> file.<H4><FONT COLOR="#000077">TYPE: Listing 9.12. New functions added to the CDVTestDocclass.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>CString CDVTestDoc::GetName( int nIndex ) const</TT><TT>{</TT><TT>    ASSERT( nIndex &lt; m_arNames.GetSize() );</TT><TT>    return m_arNames[nIndex];</TT><TT>}</TT><TT>int CDVTestDoc::AddName( const CString&amp; szName )</TT><TT>{</TT><TT>    return m_arNames.Add( szName );</TT><TT>}</TT><TT>int CDVTestDoc::GetCount() const</TT><TT>{</TT><TT>    return m_arNames.GetSize();</TT><TT>}</TT></FONT></PRE><P>Every document class must specify some access functions to add and retrieve data.The three functions in Listing 9.12 are typical access functions in that they donot just expose the <TT>CArray</TT> template. The data could also be stored in anothertype of collection. Storing the data in a <TT>CArray</TT> object is an implementationdetail that should not be of interest to users of the <TT>CDVTestDoc</TT> class.This enables the internal implementation of <TT>CDVTestDoc</TT> to be changed inthe future, if necessary.<H3><FONT COLOR="#000077"><B>Initializing a Document's Contents</B></FONT></H3><P>You create and initialize document objects in two different ways, depending onthe type of application using the document:<UL>	<LI>A new MDI document object is created for every new document opened by the program.<BR>	<BR>		<LI>SDI programs create a single document object that is reinitialized each time	a new document is opened.</UL><P>In most cases, the best place to perform any initialization is in the <TT>CDocument::OnNewDocument</TT>member function. This function is provided with some default code inserted by AppWizard.Edit the <TT>OnNewDocument</TT> function so it looks like the code provided in Listing9.13.<H4><FONT COLOR="#000077">TYPE: Listing 9.13. Changes to the CDVTestDoc::OnNewDocumentmember function.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>BOOL CDVTestDoc::OnNewDocument()</TT><TT>{</TT><TT>    TRACE( &quot;CDVTest::OnNewDocument&quot; );</TT><TT>    if (!CDocument::OnNewDocument())</TT><TT>        return FALSE;</TT><TT>    m_arNames.RemoveAll();</TT><TT>    m_arNames.Add( &quot;Curly&quot; );</TT><TT>    m_arNames.Add( &quot;Moe&quot; );</TT><TT>    m_arNames.Add( &quot;Shemp&quot; );</TT><TT>    return TRUE;</TT><TT>}</TT></FONT></PRE><P>Listing 9.13 clears the contents of the <TT>m_arNames</TT> collection and addsthree new names.<BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Time Saver:</B></FONT><B> </B>The <TT>TRACE</TT>	macro sends an output message to the compiler's debug window, which displays useful	information as the program executes.<BR>	In Listing 9.13, the <TT>TRACE</TT> macro will display a line of text when a new	document is created. It's a good idea to have your program provide tracing information	whenever an interesting event occurs. <HR></BLOCKQUOTE><H3><FONT COLOR="#000077"><B>Getting the Document Pointer</B></FONT></H3><P>Every view is associated with only one document. When a view must communicatewith its associated document, the <TT>GetDocument</TT> function is used. If the viewis created by AppWizard, as <TT>CDVTestView</TT> is, the <TT>GetDocument</TT> functionreturns a pointer to the proper document type. Listing 9.14 is a version of <TT>OnDraw</TT>that uses <TT>GetDocument</TT> to retrieve a pointer to the <TT>CDVTestDoc</TT> class;then it uses the pointer to collect the names contained in the document.<H4><FONT COLOR="#000077">TYPE: Listing 9.14. Using GetDocument to fetch a documentpointer.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>void CDVTestView::OnDraw(CDC* pDC)</TT><TT>{</TT><TT>    CDVTestDoc* pDoc = GetDocument();</TT><TT>    ASSERT_VALID(pDoc);</TT><TT>    // Calculate the space required for a single</TT><TT>    // line of text, including the inter-line area.</TT><TT>    TEXTMETRIC  tm;</TT><TT>    pDC-&gt;GetTextMetrics( &amp;tm );</TT><TT>    int nLineHeight = tm.tmHeight + tm.tmExternalLeading;</TT><TT>    CPoint  ptText( 0, 0 );</TT><TT>    for( int nIndex = 0; nIndex &lt; pDoc-&gt;GetCount(); nIndex++ )</TT><TT>    {</TT><TT>        CString szName = pDoc-&gt;GetName( nIndex );</TT><TT>        pDC-&gt;TextOut( ptText.x, ptText.y, szName );</TT><TT>        ptText.y += nLineHeight;</TT><TT>    }</TT><TT>}</TT></FONT></PRE><P>There are three main parts to Listing 9.14:<UL>	<LI>In the first part, the document pointer is retrieved using <TT>GetDocument</TT>.	The pointer value is validated using the <TT>ASSERT_VALID</TT> macro. You should	always use this macro after an old-style cast to ensure that the pointer is accurate.<BR>	<BR>		<LI>In the second part, the size of a line of text is calculated using the <TT>CDC::GetTextMetrics</TT>	function. This function fills the <TT>TEXTMETRICS</TT> structure with information	about the current font used by the device context. The <TT>tmHeight</TT> member is	the maximum height of a character, and the <TT>tmExternalLeading</TT> member is the	spacing between character lines. Adding these two values together results in a good	spacing value between displayed rows of text.<BR>	<BR>		<LI>Finally, the third part collects each name in turn from the document, using the	functions added earlier to the document class. After each line of text is displayed,	the <TT>ptText.x</TT> value is increased by the line spacing value calculated earlier.</UL><P>Compile and run the DVTest project. DVTest displays the names stored in the documentclass, as shown in Figure 9.6.</P><P><A NAME="06"></A><A HREF="06.htm"><B>Figure 9.6.</B> </A><I><BR>DVTest displays three names in its view window.</I></P><P>In Hour 22, &quot;Serialization,&quot; you'll learn how to save the document toa file. In Hour 23, &quot;Advanced Views,&quot; you'll extend DVTest to include multipleviews; one view will enable you to add names to the document.<H2><FONT COLOR="#000077"><B>Summary</B></FONT></H2><P>In this hour you've learned about pointers and references, as well as the basicDocument/View architecture used in most MFC programs. You learned how to use AppWizardand ClassWizard in SDI and MDI applications, and created a sample program demonstratingthe use of Document/View.<H2><FONT COLOR="#000077"><B>Q&amp;A</B></FONT></H2><DL>	<DD><B>Q When I use pointers, sometimes I get an Unhandled Exception error from Windows	and my program crashes. The code that causes the problem looks something like this:</B></DL><BLOCKQUOTE>	<PRE><FONT COLOR="#0066FF"><TT>int *pBadInt;</TT><TT>*pBadInt = 42;   // Error here</TT></FONT></PRE></BLOCKQUOTE><PRE><FONT COLOR="#0066FF"><TT></TT></FONT></PRE><DL>	<DD><B>A</B> There are two problems. First, the pointer isn't initialized. You should	always initialize a pointer to either <TT>NULL</TT> or to an area of memory that	is dynamically allocated, like this:</DL><BLOCKQUOTE>	<PRE><FONT COLOR="#0066FF"><TT>int *pInt = NULL;</TT><TT>int *pInt = new int;</TT></FONT></PRE></BLOCKQUOTE><PRE><FONT COLOR="#0066FF"><TT></TT></FONT></PRE><DL>	<DD>A pointer doesn't automatically set aside any storage area--in the preceding	code, <TT>pBadInt</TT> is uninitialized and is pointing to a random area of memory.	You must assign the pointer either an address of an existing variable or the address	of a block of dynamically allocated memory:</DL><BLOCKQUOTE>	<PRE><FONT COLOR="#0066FF"><TT>int n;</TT><TT>int *pInt;</TT><TT>pInt = &amp;n;</TT><TT>*pInt = 42;   // Okay</TT><TT>pInt = new int;</TT><TT>*pInt = 42;   // Okay</TT><TT>delete pInt;</TT></FONT></PRE></BLOCKQUOTE><PRE><FONT COLOR="#0066FF"><TT></TT></FONT></PRE><DL>	<DD><B>Q I don't get all this Document/View stuff. Wouldn't it be easier to store	all the data in the view class?</B><BR>	<BR>	<B>A</B> It might seem easier at first. However, the MFC framework will provide a	great deal of help for free if you follow the Document/View rules. For example, if	you try to store your data in your view class, it will be very difficult to provide	multiple views for the same document. As you will see in Hour 23, it's fairly straightforward	if you follow the Document/View model. Also, as you will see in Hour 22, MFC gives	you a great deal of support for loading and storing data stored in your document	classes.</DL><H2><FONT COLOR="#000077"><B>Workshop</B></FONT></H2><P>The Workshop is designed to help you anticipate possible questions, review whatyou've learned, and begin thinking ahead to putting your knowledge into practice.The answers to the quiz are in Appendix B, &quot;Quiz Answers.&quot;<H3><FONT COLOR="#000077"><B>Quiz</B></FONT></H3><DL>	<DD>1. What is the <TT>sizeof</TT> operator used for?<BR>	<BR>	2. What are some of the differences between pointers and references?<BR>	<BR>	3. What is more efficient to pass as a parameter--a pointer or an object? Why?<BR>	<BR>	4. What keyword is used to dynamically allocate memory?<BR>	<BR>	5. What keyword is used to release dynamically allocated memory?<BR>	<BR>	6. In the Document/View architecture, which classes are responsible for maintaining	the user interface?<BR>	<BR>	7. What are the four main categories of classes in the Document/View architecture?<BR>	<BR>	8. What part of the Document/View architecture is responsible for the application's	data?<BR>	<BR>	9. What <TT>CView</TT> member function is used to retrieve a pointer to the document	associated with the view?<BR>	<BR>	10. What <TT>CDocument</TT> member function is used to notify a document's views	that their user interface might need to be updated?</DL><H3><FONT COLOR="#000077"><B>Exercises</B></FONT></H3><DL>	<DD>1. Use the <TT>TRACE</TT> macro to see when the view requests information from	the document. Add a <TT>TRACE</TT> macro to the document's <TT>GetName</TT> function,	and experiment with resizing and moving the view to see when the view requests the	data.<BR>	<BR>	2. Modify the DVTest project so that a line number is displayed for each item in	the view.<FONT COLOR="#000077"></FONT></DL><CENTER><P><HR><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> <BR><BR><BR><IMG SRC="../button/corp.gif" WIDTH="284" HEIGHT="45" ALIGN="BOTTOM" ALT="Macmillan Computer Publishing USA"BORDER="0"></P><P>&#169; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费观看在线色综合| 日韩成人免费在线| 麻豆成人综合网| 3d成人动漫网站| 中文字幕va一区二区三区| 国内外精品视频| 日韩欧美一级二级| 紧缚奴在线一区二区三区| 欧美曰成人黄网| 亚洲欧美电影一区二区| 91麻豆国产精品久久| 亚洲精品成人天堂一二三| 国内欧美视频一区二区| 日韩一区二区免费视频| 免费高清在线一区| 久久新电视剧免费观看| 国产69精品久久久久777| 国产精品视频看| 日本丶国产丶欧美色综合| 午夜久久福利影院| 91精品久久久久久久91蜜桃| 免费一级欧美片在线观看| 亚洲少妇屁股交4| 欧美精品少妇一区二区三区| 国产精品香蕉一区二区三区| 国产精品久线在线观看| 欧洲国内综合视频| 国产美女娇喘av呻吟久久| 亚洲视频一区二区免费在线观看| 在线观看www91| 国产一区不卡精品| 中文字幕亚洲视频| 欧美精品日韩一区| 99久精品国产| 国产精品一级黄| 亚洲高清久久久| 中文字幕在线观看一区| 欧美一区二区福利视频| 欧美日韩中字一区| 色哟哟日韩精品| 国产a视频精品免费观看| 亚洲在线观看免费| 中文字幕在线观看一区| 久久综合成人精品亚洲另类欧美| 欧美日韩国产大片| 337p亚洲精品色噜噜狠狠| 一本大道久久精品懂色aⅴ| 成人av在线播放网址| 国产精品一区二区在线播放 | 北条麻妃国产九九精品视频| 久久成人免费电影| 亚洲成a天堂v人片| 天天色图综合网| 亚洲一区二区三区三| 一区二区在线观看视频在线观看| 中文字幕在线不卡一区| 成人欧美一区二区三区视频网页| 中文字幕av资源一区| 国产精品传媒入口麻豆| 国产精品毛片久久久久久| 国产欧美日韩精品在线| 国产婷婷色一区二区三区| 国产片一区二区| 亚洲欧美偷拍三级| 午夜精品久久久久久| 麻豆成人免费电影| 国产91综合一区在线观看| 成人福利电影精品一区二区在线观看| 国产成人av电影在线观看| 色综合色综合色综合色综合色综合| 99精品视频在线观看| 欧美剧情片在线观看| 日韩视频一区二区在线观看| 国产拍揄自揄精品视频麻豆| 亚洲欧洲日韩一区二区三区| 亚洲一区在线播放| 国产精品一区二区91| 欧美亚洲尤物久久| 日韩精品一区在线观看| 国产日产亚洲精品系列| 一区二区三区四区不卡在线 | 91激情在线视频| 精品国内片67194| 国产精品大尺度| 国产乱国产乱300精品| 91同城在线观看| 日韩美女久久久| 国产成人精品免费在线| 久久综合色8888| 美女网站在线免费欧美精品| 日韩午夜精品视频| 日韩高清不卡在线| 欧美精品1区2区| 久久国产欧美日韩精品| 精品国产乱码久久久久久浪潮 | 亚洲视频在线观看三级| 国产91精品免费| 国产精品国产三级国产三级人妇 | 黄色精品一二区| 精品久久久网站| 国产在线播放一区三区四| 久久久国产午夜精品| 日韩欧美国产综合在线一区二区三区| 欧美日韩一区精品| 午夜精品一区在线观看| 538在线一区二区精品国产| 青青草国产成人av片免费| 日韩欧美国产不卡| 国产.欧美.日韩| 亚洲一区中文日韩| 久久精品人人爽人人爽| 在线区一区二视频| 另类综合日韩欧美亚洲| 中文字幕中文字幕一区| 欧美性xxxxxxxx| 国内成+人亚洲+欧美+综合在线| 中文字幕视频一区二区三区久| 欧美午夜在线一二页| 国产精品一色哟哟哟| 17c精品麻豆一区二区免费| 日韩一级黄色片| 99re这里只有精品视频首页| 91一区二区在线观看| 久久成人麻豆午夜电影| 一个色在线综合| 久久精品一区二区三区不卡 | 国产精品国产三级国产有无不卡 | 国产精品一区在线| 亚洲成人动漫精品| 国产精品成人免费在线| 久久综合久久综合亚洲| 91精品国产综合久久香蕉的特点| 91视频一区二区三区| 久久久久久久久久久电影| 91小视频免费观看| av成人老司机| 成人app在线| 国产成人自拍高清视频在线免费播放| 青青草成人在线观看| 亚洲国产乱码最新视频| 亚洲在线中文字幕| 亚洲国产欧美另类丝袜| 亚洲在线视频免费观看| 亚洲国产另类av| 午夜精品福利久久久| 五月综合激情婷婷六月色窝| 婷婷综合另类小说色区| 日韩中文字幕亚洲一区二区va在线| 亚洲成人动漫精品| 五月开心婷婷久久| 美女性感视频久久| 国产成人综合网站| 欧美在线观看你懂的| 欧美一级xxx| 国产女人aaa级久久久级| 久久精品国产一区二区| 韩国欧美国产1区| 在线视频一区二区免费| 欧美日韩视频在线第一区| 日韩一级二级三级| 亚洲老妇xxxxxx| 狠狠色丁香九九婷婷综合五月| 91免费小视频| 欧美va亚洲va| 日本一二三不卡| 国产日韩欧美精品在线| 国产精品卡一卡二卡三| 中文字幕在线一区免费| 亚洲一区二区三区中文字幕 | 久久综合av免费| 亚洲精品你懂的| 国产一区二区精品在线观看| 成人sese在线| 欧美精品一二三| 久久精品一区二区三区四区| 亚洲欧美日韩国产综合| 九一久久久久久| 91亚洲精品久久久蜜桃网站 | 色噜噜狠狠色综合中国| 欧美一区二区视频免费观看| 国产精品免费看片| 麻豆免费精品视频| 欧美日韩一卡二卡三卡| 国产日产欧美一区| 久久国产日韩欧美精品| 欧美日韩中文字幕一区| 久久精品亚洲精品国产欧美kt∨| 亚洲一区二区三区视频在线播放| 国产乱码精品一区二区三区忘忧草 | 99re亚洲国产精品| 久久蜜桃一区二区| 男人的j进女人的j一区| 色综合久久中文综合久久97| 26uuu久久天堂性欧美| 五月天激情综合| 成人丝袜高跟foot| 国产欧美在线观看一区| 国产一区二区三区综合| 欧美va亚洲va| 高潮精品一区videoshd|