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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? 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()

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人h版在线观看| 蜜臀av性久久久久蜜臀aⅴ| 成人免费看黄yyy456| 2024国产精品| 激情综合色播激情啊| 久久久亚洲午夜电影| 粉嫩av一区二区三区| 中文字幕一区二区三区蜜月 | 三级在线观看一区二区| 欧美美女黄视频| 美女国产一区二区| 日本一区二区三区电影| 色视频欧美一区二区三区| 国产福利一区在线| 国产精品乱码一区二区三区软件| 91在线视频在线| 午夜精品久久一牛影视| 日韩精品一区二区三区三区免费| 国产乱码一区二区三区| 亚洲人成网站在线| 日韩一级黄色片| 99精品久久99久久久久| 视频一区二区三区在线| 欧美激情一区二区三区不卡| 日本久久电影网| 国产真实乱对白精彩久久| 亚洲欧美一区二区三区久本道91| 91.com在线观看| 成人做爰69片免费看网站| 亚洲成人午夜电影| 国产午夜三级一区二区三| 欧美午夜电影在线播放| 美国精品在线观看| 一区二区在线观看免费 | 99国产精品久久久| 秋霞电影一区二区| 日韩伦理电影网| 精品久久久网站| 欧美日韩在线三级| 精品欧美久久久| 欧美无人高清视频在线观看| 国产一区二区三区免费| 偷拍一区二区三区| 国产精品麻豆视频| 精品美女一区二区三区| 欧美精品国产精品| 91丝袜国产在线播放| 国产精品一区二区久久精品爱涩 | 一本大道久久a久久精品综合| 麻豆精品一二三| 一区二区三区四区在线免费观看| 久久麻豆一区二区| 日韩欧美三级在线| 欧美日本一区二区三区| 91尤物视频在线观看| 国产精品自拍av| 免费视频一区二区| 午夜视频一区二区| 亚洲综合在线五月| 最新国产精品久久精品| 久久女同性恋中文字幕| 日韩精品一区二区三区在线播放| 在线免费观看日本一区| 成人激情免费网站| 国产福利精品一区二区| 精品亚洲免费视频| 毛片av中文字幕一区二区| 视频一区视频二区中文| 亚洲第一福利一区| 亚洲在线视频免费观看| 亚洲视频图片小说| 日韩一区有码在线| 亚洲视频免费在线观看| 亚洲视频在线一区二区| 中文字幕亚洲区| 综合久久久久久| 亚洲免费在线看| 亚洲精品国久久99热| 亚洲影视在线播放| 五月天婷婷综合| 日韩中文欧美在线| 久久精品国产一区二区三区免费看| 男女男精品视频| 精品亚洲国产成人av制服丝袜| 久久狠狠亚洲综合| 国产91精品一区二区| 国产成人午夜高潮毛片| 9i看片成人免费高清| 色综合久久66| 欧美日韩不卡在线| 日韩欧美一二三| 中文字幕不卡一区| 亚洲制服丝袜av| 奇米精品一区二区三区四区| 韩国欧美一区二区| 高清久久久久久| 91一区一区三区| 欧美疯狂做受xxxx富婆| 欧美zozo另类异族| 国产精品伦理一区二区| 亚洲一区二区三区四区在线| 日本成人中文字幕| 国产成人精品网址| 色欧美片视频在线观看| 欧美一区二区三区视频在线| 国产三级精品三级| 亚洲精品国产高清久久伦理二区| 午夜精品久久久久| 国产精品一区二区免费不卡 | 日本大香伊一区二区三区| 91精品午夜视频| 亚洲国产精品黑人久久久| 亚洲精品乱码久久久久久黑人 | 成人黄色网址在线观看| 91久久精品网| 久久亚洲影视婷婷| 亚洲一区二区3| 国产精品一级黄| 欧美羞羞免费网站| 国产日韩欧美一区二区三区乱码 | 日韩欧美视频一区| 中文字幕在线不卡一区 | 亚洲一二三四区不卡| 国产做a爰片久久毛片| 91碰在线视频| 久久婷婷国产综合国色天香| 亚洲欧美日韩中文播放| 狠狠色综合色综合网络| 日本韩国精品一区二区在线观看| 精品国产免费人成电影在线观看四季 | 无码av中文一区二区三区桃花岛| 成人免费高清在线| 日韩欧美高清一区| 亚洲综合清纯丝袜自拍| 粉嫩绯色av一区二区在线观看| 欧美一区二区福利在线| 一区二区三区鲁丝不卡| 成人免费视频网站在线观看| 欧美大片顶级少妇| 亚洲国产cao| 色屁屁一区二区| 精品一区二区综合| 欧美日韩aaaaa| 亚洲一二三专区| 一本色道久久综合狠狠躁的推荐| 精品国产区一区| 麻豆精品国产91久久久久久| 日本高清不卡一区| 亚洲女厕所小便bbb| 成人免费观看视频| 国产欧美一区二区在线| 久久不见久久见免费视频7| 欧美视频一区二区在线观看| 一区二区三区中文字幕精品精品| 成人99免费视频| 国产精品网站在线观看| 国产99久久久国产精品免费看| 精品国产91亚洲一区二区三区婷婷 | 亚洲另类中文字| 不卡电影一区二区三区| 国产精品久久久久一区二区三区共| 精品一区二区久久| 26uuu亚洲| 精品制服美女久久| 精品奇米国产一区二区三区| 激情综合网av| 久久综合九色综合久久久精品综合| 免费看黄色91| 欧美刺激午夜性久久久久久久| 日韩电影在线一区| 日韩三级av在线播放| 久久99国产乱子伦精品免费| 日韩三级精品电影久久久| 另类小说视频一区二区| 26uuu色噜噜精品一区| 国产精品一区专区| 国产精品麻豆网站| 日本韩国一区二区三区| 亚洲一二三四区不卡| 欧美网站大全在线观看| 日韩中文字幕1| 久久综合成人精品亚洲另类欧美| 国产成人午夜99999| 中文字幕欧美一| 欧美日韩国产高清一区二区| 免费观看30秒视频久久| 国产婷婷色一区二区三区| 99精品视频在线观看| 亚洲va国产va欧美va观看| 欧美一级国产精品| 国产中文一区二区三区| 国产色一区二区| 91玉足脚交白嫩脚丫在线播放| 亚洲一区二区精品久久av| 日韩美女一区二区三区| 成人av综合在线| 日韩av网站在线观看| 国产亚洲精品久| 欧美三级韩国三级日本三斤| 麻豆成人91精品二区三区|