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

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

?? ch07.htm

?? Learning language of Visual C++6
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!--

function popUp(pPage) {
 var fullURL = document.location;
 var textURL = fullURL.toString();
 var URLlen = textURL.length;
 var lenMinusPage = textURL.lastIndexOf("/");
 lenMinusPage += 1;
 var fullPath = textURL.substring(0,lenMinusPage);
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '<link rel="stylesheet" href="/includes/stylesheets/ebooks.css"></head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + fullPath + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
 // Johnny Jackson 4/28/98
 }

//-->
                                                                
</SCRIPT>
<link rel="stylesheet" href="/includes/stylesheets/ebooks.css">

	
	<TITLE>Special Edition Using Visual C++ 6 -- Ch 7 -- Persistence and File I/O</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/que.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
Special Edition Using Visual C++ 6</H1>
</CENTER>
<CENTER>
<P><A HREF="../ch06/ch06.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch08/ch08.htm"><IMG
SRC="../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>- 7 -</H1>
</CENTER>
<CENTER>
<H1>Persistence and File I/O</H1>
</CENTER>

<UL>
	<LI><A HREF="#Heading1">Understanding Objects and Persistence</A>
	<LI><A HREF="#Heading2">Examining the File Demo Application</A>
	<UL>
		<LI><A HREF="#Heading3">A Review of Document Classes</A>
		<LI><A HREF="#Heading4">Building the File Demo Application</A>
	</UL>
	<LI><A HREF="#Heading5">Creating a Persistent Class</A>
	<UL>
		<LI><A HREF="#Heading6">The File Demo 2 Application</A>
		<LI><A HREF="#Heading7">Looking at the CMessages Class</A>
		<LI><A HREF="#Heading8">Using the CMessages Class in the Program</A>
	</UL>
	<LI><A HREF="#Heading9">Reading and Writing Files Directly</A>
	<UL>
		<LI><A HREF="#Heading10">The CFile Class</A>
	</UL>
	<LI><A HREF="#Heading11">Creating Your Own CArchive Objects</A>
	<LI><A HREF="#Heading12">Using the Registry</A>
	<UL>
		<LI><A HREF="#Heading13">How the Registry Is Set Up</A>
		<LI><A HREF="#Heading14">The Predefined Keys</A>
		<LI><A HREF="#Heading15">Using the Registry in an MFC Application</A>
		<LI><A HREF="#Heading16">The Sample Applications Revisited</A>
	</UL>
</UL>

<P>
<HR SIZE="4">

<CENTER>
<H1></H1>
</CENTER>
<H2><A NAME="Heading1"></A>Understanding Objects and Persistence</H2>
<P>One of the most important things a program must do is save users' data after that
data is changed in some way. Without the capability to save edited data, the work
a user performs with an application exists only as long as the application is running,
vanishing the instant the user exits the application. Not a good way to get work
done! In many cases, especially when using AppWizard to create an application, Visual
C++ provides much of the code necessary to save and load data. However, in some cases--most
notably when you create your own object types--you have to do a little extra work
to keep your users' files up to date.</P>
<P>When you're writing an application, you deal with a lot of different object types.
Some data objects might be simple types, such as integers and characters. Other objects
might be instances of classes, such as strings from the CString class or even objects
created from your own custom classes. When using objects in applications that must
create, save, and load documents, you need a way to save and load the state of those
objects so that you can re-create them exactly as users left them at the end of the
last session.</P>
<P>An object's capability to save and load its state is called <I>persistence</I>.
Almost all MFC classes are persistent because they're derived directly or indirectly
from MFC's CObject class, which provides the basic functionality for saving and loading
an object's state. The following section reviews how MFC makes a document object
persistent.</P>
<P>
<H2><A NAME="Heading2"></A>Examining the File Demo Application</H2>
<P>When you use Visual C++'s AppWizard to create a program, you get an application
that uses document and view classes to organize, edit, and display its data. As discussed
in Chapter 4, &quot;Documents and Views,&quot; the document object, derived from
the CDocument class, is responsible for holding the application's data during a session
and for saving and loading the data so that the document persists from one session
to another.</P>
<P>In this chapter, you'll build the File Demo application, which demonstrates the
basic techniques behind saving and loading data of an object derived from CDocument.
File Demo's document is a single string containing a short message, which the view
displays.</P>
<P>Three menu items are relevant in the File Demo application. When the program first
begins, the message is automatically set to the string Default Message. Users will
change this message by choosing Edit, Change Message. The File, Save menu option
saves the document, as you'd expect, and File, Open reloads it from disk.</P>
<P>
<H3><A NAME="Heading3"></A>A Review of Document Classes</H3>
<P>Anyone who's written a program has experienced saving and opening files--object
persistence from the user's point of view. In this chapter you'll learn how persistence
works. Although you had some experience with document classes in Chapter 4, you'll
now review the basic concepts with an eye toward extending those concepts to your
own custom classes.</P>
<P>When working with an application created by AppWizard, you must complete several
steps to enable your document to save and load its state. Those steps are discussed
in this section. The steps are as follows:</P>

<DL>
	<DD><B>1. </B>Define the member variables that will hold the document's data.
	<P>
	<DT></DT>
	<DD><B>2. </B>Initialize the member variables in the document class's OnNewDocument()
	member function.
	<P>
	<DT></DT>
	<DD><B>3. </B>Display the current document in the view class's OnDraw() member function.
	<P>
	<DT></DT>
	<DD><B>4. </B>Provide member functions in the view class that enable users to edit
	the document.
	<P>
	<DT></DT>
	<DD><B>5. </B>Add to the document class's Serialize() member function the code needed
	to save and load the data that comprises the document.
	<P>
</DL>

<P>When your application can handle multiple documents, you need to do a little extra
work to be sure that you use, change, or save the correct document. Luckily, most
of that work is taken care of by MFC and AppWizard.</P>
<P>
<H3><A NAME="Heading4"></A>Building the File Demo Application</H3>
<P>To build the File Demo application, start by using AppWizard to create an SDI
application. All the other AppWizard choices should be left at their default values,
so you can speed things up by clicking Finish on Step 1 after selecting SDI and making
sure that Document/View support is selected.</P>
<P>Double-click CfileDemoDoc in ClassView to edit the header file for the document
class. In the Attributes section add a CString member variable called m_message,
so that the Attributes section looks like this:</P>
<P>
<PRE>// Attributes
public:
    CString m_message;
</PRE>
<P>In this case, the document's storage is nothing more than a single string object.
Usually, your document's storage needs are much more complex. This single string,
however, is enough to demonstrate the basics of a persistent document. It's very
common for MFC programmers to use public variables in their documents, rather than
a private variable with public access functions. It makes it a little simpler to
write the code in the view class that will access the document variables. It will,
however, make future enhancements a little more work. These tradeoffs are discussed
in more detail in Appendix A, &quot;C++ Review and Object-Oriented Concepts.&quot;</P>
<P>This string, like all the document's data, must be initialized. The OnNewDocument()
member function is the place to do it. Expand CFileDemoDoc in ClassView and double-click
OnNewDocument() to edit it. Add a line of code to initialize the string so that the
function looks like Listing 7.1. You should remove the TODO comments because you've
done what they were reminding you to do.</P>
<P>
<H4>Listing 7.1&#160;&#160;Initializing the Document's Data</H4>
<PRE>BOOL CFileDemoDoc::OnNewDocument()
{
    if (!CDocument::OnNewDocument())
        return FALSE;
    m_message = &quot;Default Message&quot;;
    return TRUE;
</PRE>
<PRE>}
</PRE>
<P>With the document class's m_message data member initialized, the application can
display the data in the view window. You just need to edit the view class's OnDraw()
function (see Listing 7.2). Expand CFileDemoView in ClassView and double-click OnDraw()
to edit it. Again, you're just adding one line of code and removing the TODO comment.</P>
<P>
<H4>Listing 7.2&#160;&#160; Displaying the Document's Data</H4>
<PRE>void CFileDemoView::OnDraw(CDC* pDC)
{
    CFileDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    pDC-&gt;TextOut(20, 20, pDoc-&gt;m_message);
</PRE>
<PRE>}
</PRE>
<P>Getting information onscreen, using device contexts, and the TextOut() function
are all discussed in Chapter 5, &quot;Drawing on the Screen.&quot;</P>
<P>Build File Demo now, to make sure there are no typos, and run it. You should see
Default Message appear onscreen.</P>
<P>Now, you need to allow users to edit the application's document by changing the
string. In theory, the application should display a dialog box to let the user enter
any desired string at all. For our purposes, you're just going to have the Edit,
Change Message menu option assign the string a different, hard-coded value. ShowString,
the subject of Chapter 8, &quot;Building a Complete Application: ShowString,&quot;
shows how to create a dialog box such as the one File Demo might use.</P>
<P>Click the Resource tab to switch to ResourceView, expand the resources, expand
Menus, and double-click IDR_MAINFRAME to edit it. Click once on the Edit item in
the menu you are editing to drop it down. Click the blank item at the end of the
list and type <B>Change &amp;Message</B>. This will add another item to the menu.</P>
<P>Choose View, ClassWizard to make the connection between this menu item and your
code. You should see ID_EDIT_CHANGEMESSAGE highlighted already; if not, click it
in the box on the left to highlight it. Choose CFileDemoView from the drop-down box
on the upper right. Click COMMAND in the lower-right box and then click the Add Function
button. Accept the suggested name, OnEditChangemessage(), by clicking OK on the dialog
that appears. Click Edit Code to open the new function in the editor and edit it
to match Listing 7.3.</P>
<P>
<H4>Listing 7.3&#160;&#160;Changing the Document's Data</H4>
<PRE>void CFileDemoView::OnEditChangemessage() 
{
   CTime now = CTime::GetCurrentTime();
   CString changetime = now.Format(&quot;Changed at %B %d %H:%M:%S&quot;);
   GetDocument()-&gt;m_message = changetime;
   GetDocument()-&gt;SetModifiedFlag();
   Invalidate();
</PRE>
<PRE>}
</PRE>
<P>This function, which responds to the application's Edit, Change Message command,
builds a string from the current date and time and transfers it to the document's
data member. (The CTime class and its Format() function are discussed in Appendix
F, &quot;Useful Classes.&quot;) The call to the document class's SetModifiedFlag()
function notifies the object that its contents have been changed. The application
will warn about exiting with unsaved changes as long as you remember to call SetModifiedFlag()

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一区男女天堂| 美女一区二区在线观看| 亚洲日穴在线视频| 奇米综合一区二区三区精品视频 | 精品99一区二区三区| 亚洲精品成a人| 色综合一个色综合| 综合电影一区二区三区| 国产成人精品三级| 中文字幕亚洲精品在线观看| 精品国偷自产国产一区| 亚洲va国产天堂va久久en| 99麻豆久久久国产精品免费优播| 精品国产免费一区二区三区香蕉| 首页综合国产亚洲丝袜| 国产一区二区在线免费观看| 久久久精品国产免费观看同学| 麻豆精品蜜桃视频网站| 精彩视频一区二区| 欧美裸体一区二区三区| 一区二区三国产精华液| 97精品久久久午夜一区二区三区| 国产精品国产自产拍高清av| 99国产精品久久久久久久久久| 欧美mv日韩mv国产网站app| 国内精品视频一区二区三区八戒| 欧美国产成人精品| 亚洲欧洲性图库| 成人毛片在线观看| 洋洋成人永久网站入口| 欧美日韩成人在线| 麻豆精品一区二区| 国产精品久久久久7777按摩| 99国产精品99久久久久久| 欧美三级电影精品| 久久婷婷综合激情| 91精品国产福利在线观看| 日本aⅴ免费视频一区二区三区 | 欧美日韩一级二级| 亚洲一区二区三区在线看| 欧美一区二区网站| 在线精品视频免费观看| 日韩理论片一区二区| 国产精品亚洲第一| 欧美国产日韩亚洲一区| 精品视频一区三区九区| 国产成人午夜精品5599| 亚洲午夜久久久| 国产精品私房写真福利视频| 欧洲一区在线观看| 成人动漫在线一区| 中文在线一区二区| 日本韩国一区二区三区视频| 久久爱www久久做| 亚洲aⅴ怡春院| 亚洲女子a中天字幕| 中文字幕av免费专区久久| 国产精品系列在线播放| 一本大道综合伊人精品热热| 免费美女久久99| 老汉av免费一区二区三区 | 不卡视频免费播放| 国产精品一区在线观看你懂的| 岛国精品在线观看| 91偷拍与自偷拍精品| 777色狠狠一区二区三区| 欧美一区二区视频在线观看2020| 日韩欧美色综合| 国产精品久久久一区麻豆最新章节| 欧美伊人精品成人久久综合97 | 国产精品污www在线观看| 亚洲精品日韩一| 美女视频黄 久久| 成人黄页毛片网站| 欧美吻胸吃奶大尺度电影| 欧美精品一区二区三区久久久| 久久精品亚洲一区二区三区浴池| 一区二区三区高清| 亚洲国产日韩综合久久精品| 中文字幕电影一区| 国产精品素人一区二区| 亚洲激情在线播放| 青青草原综合久久大伊人精品优势| 国产自产视频一区二区三区| 欧美亚洲国产怡红院影院| 国产精品福利一区二区| 国产精品99久久久久久宅男| 欧美色精品在线视频| 日韩一区二区中文字幕| 精品三级在线观看| 亚洲国产精品av| 全国精品久久少妇| 不卡在线观看av| 91麻豆精品国产91久久久使用方法| 欧美久久免费观看| 国产亚洲一区二区三区四区| 亚洲免费看黄网站| 久久99精品久久久久久动态图| 丁香婷婷综合网| 欧美久久久久久久久中文字幕| 久久久天堂av| 美女国产一区二区三区| 91久久精品一区二区三| 亚洲视频一二三区| 丰满少妇久久久久久久| 宅男噜噜噜66一区二区66| 蜜臀av亚洲一区中文字幕| 欧美日韩国产a| 全国精品久久少妇| 91精品国产高清一区二区三区 | 99v久久综合狠狠综合久久| 日韩免费视频线观看| 美女一区二区视频| 在线综合视频播放| 国产精品456露脸| 国产日产精品一区| 国产98色在线|日韩| 91麻豆自制传媒国产之光| 成人一道本在线| 一区二区三区在线观看欧美 | 日韩成人一级大片| 久久久久久久久久看片| 精品视频一区三区九区| 成人avav影音| 久久丁香综合五月国产三级网站| 欧美一区二区三区播放老司机| 久久国产精品99久久人人澡| 日韩欧美成人一区| 成人国产免费视频| 蜜臀a∨国产成人精品| 久久影院视频免费| 欧美日韩亚洲高清一区二区| 高清不卡在线观看| 老司机精品视频在线| 亚洲国产精品传媒在线观看| 欧美伊人久久久久久久久影院| 激情都市一区二区| 亚洲综合激情小说| 中文无字幕一区二区三区| 欧美精品一卡二卡| 色婷婷精品久久二区二区蜜臀av| 麻豆91小视频| 亚洲国产精品一区二区久久恐怖片| 26uuu精品一区二区三区四区在线| 欧美色图免费看| 93久久精品日日躁夜夜躁欧美| 亚洲综合另类小说| 亚洲欧洲制服丝袜| 亚洲品质自拍视频| 国产精品电影一区二区三区| 欧美午夜不卡视频| 日本乱人伦一区| 欧美一区二区免费| 亚洲人成影院在线观看| 亚洲观看高清完整版在线观看| 日本成人中文字幕在线视频| 国产伦精品一区二区三区视频青涩 | 中文字幕欧美日韩一区| 精品国产网站在线观看| 亚洲三级小视频| 美国三级日本三级久久99| av电影在线观看完整版一区二区| 色婷婷综合激情| 精品国产3级a| 亚洲国产欧美在线| 成人激情av网| 欧美放荡的少妇| 国产精品麻豆欧美日韩ww| 午夜欧美在线一二页| 91同城在线观看| www成人在线观看| 午夜一区二区三区在线观看| 婷婷中文字幕一区三区| 国产真实乱子伦精品视频| 91丨国产丨九色丨pron| 欧美人成免费网站| 综合中文字幕亚洲| 亚洲成人午夜电影| 一本色道久久综合亚洲精品按摩| 日韩欧美精品在线视频| 一区二区三区精品在线观看| 国产一区二区三区高清播放| 欧美一区二区成人| 石原莉奈在线亚洲三区| 成人黄色电影在线| 久久蜜臀中文字幕| 日韩av一二三| 9191久久久久久久久久久| 亚洲人午夜精品天堂一二香蕉| 国产.欧美.日韩| 精品不卡在线视频| 精品一区二区在线免费观看| 成人激情开心网| 久久精品在线观看| 麻豆成人久久精品二区三区小说| 国产+成+人+亚洲欧洲自线| 国产目拍亚洲精品99久久精品| 丝袜亚洲另类欧美| 日韩国产欧美三级| 69久久夜色精品国产69蝌蚪网|