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

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

?? ch07.htm

?? Learning language of Visual C++6
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
everywhere there might be a change to the data. Finally, this code forces a redraw
of the screen by calling Invalidate(), as discussed in Chapter 4.</P>


<BLOCKQUOTE>
	<P>
<HR>
<strong>TIP:</strong> If m_message was a private member variable of the document class,
	you could have a public SetMessage() function that called SetModifiedFlag() and be
	guaranteed no programmer would ever forget to call it. That's one of the advantages
	of writing truly object-oriented programs. 
<HR>


</BLOCKQUOTE>

<P>The document class's Serialize() function handles the saving and loading of the
document's data. Listing 7.4 shows the empty shell of Serialize() generated by AppWizard.</P>
<P>
<H4>Listing 7.4&#160;&#160;FILEVIEW.CPP--The Document Class Serialize() Function</H4>
<PRE>void CFileDoc::Serialize(CArchive&amp; ar)
{
    if (ar.IsStoring())
    {
        // TODO: add storing code here
}
    else
    {
        // TODO: add loading code here
}
</PRE>
<PRE>}
</PRE>
<P>Because the CString class (of which m_message is an object) defines the &gt;&gt;
and &lt;&lt; operators for transferring strings to and from an archive, it's a simple
task to save and load the document class's data. Simply add this line where the comment
reminds you to add storing code:</P>
<P>
<PRE>ar &lt;&lt; m_message;
</PRE>
<P>Add this similar line where the loading code belongs:</P>
<P>
<PRE>ar &gt;&gt; m_message;
</PRE>
<P>The &lt;&lt; operator sends the CString m_message to the archive; the &gt;&gt;
operator fills m_message from the archive. As long as all the document's member variables
are simple data types such as integers or characters, or MFC classes such as CString
with these operators already defined, it's easy to save and load the data. The operators
are defined for these simple data types:</P>

<UL>
	<LI>BYTE
	<P>
	<LI>WORD
	<P>
	<LI>int
	<P>
	<LI>LONG
	<P>
	<LI>DWORD
	<P>
	<LI>float
	<P>
	<LI>double
</UL>

<P>Build File Demo and run it. Choose Edit, Change Message, and you should see the
new string onscreen, as shown in Figure 7.1. Choose File, Save and enter a filename
you can remember. Now change the message again. Choose File, New and you'll be warned
about saving your current changes first, as in Figure 7.2. Choose File, Open and
browse to your file, or just find your filename towards the bottom of the File menu
to re-open it, and you'll see that File Demo can indeed save and reload a string.</P>
<P><A HREF="javascript:popUp('07uvc01.gif')"><B>FIG. 7.1</B></A><B> </B><I>File Demo
changes the string on command.</I></P>
<P><A HREF="javascript:popUp('07uvc02.gif')"><B>FIG. 7.2</B></A><B> </B><I>Your users
will never lose unsaved data again.</I></P>


<BLOCKQUOTE>
	<P>
<HR>
<BR>
	<strong>NOTE:[ENND] If you change the file, save it, change it again, and re-open it,
	File Demo will not ask Revert to saved document? as some applications do. Instead,
	it will bail out of the File Open process partway through and leave you with your
	most recent changes. This behavior is built in to MFC. If the name of the file you
	are opening matches the name of the file that is already open, you will not revert
	to the saved document.&#160; 
<HR>


</BLOCKQUOTE>

<H2><A NAME="Heading5"></A>Creating a Persistent Class</H2>
<P>What if you've created your own custom class for holding the elements of a document?
How can you make an object of this class persistent? You find the answers to these
questions in this section.</P>
<P>Suppose that you now want to enhance the File Demo application so that it contains
its data in a custom class called CMessages. The member variable is now called m_messages
and is an instance of CMessages. This class holds three CString objects, each of
which must be saved and loaded for the application to work correctly. One way to
arrange this is to save and load each individual string, as shown in Listing 7.5.</P>
<P>
<H4>Listing 7.5&#160;&#160; One Possible Way to Save the New Class's Strings</H4>
<PRE>void CFileDoc::Serialize(CArchive&amp; ar)
{
    if (ar.IsStoring())
    {
        ar &lt;&lt; m_messages.m_message1;
        ar &lt;&lt; m_messages.m_message2;
        ar &lt;&lt; m_messages.m_message3;
    }
    else
    {
        ar &gt;&gt; m_messages.m_message1;
        ar &gt;&gt; m_messages.m_message2;
        ar &gt;&gt; m_messages.m_message3;
}
</PRE>
<PRE>}
</PRE>
<P>You can write the code in Listing 7.5 only if the three member variables of the
CMessages class are public and if you know the implementation of the class itself.
Later, if the class is changed in any way, this code also has to be changed. It's
more object oriented to delegate the work of storing and loading to the CMessages
class itself. This requires some preparation. The following basic steps create a
class that can serialize its member variables:</P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Derive the class from CObject.
	<P>
	<DT></DT>
	<DD><B>2. </B>Place the DECLARE_SERIAL() macro in the class declaration.
	<P>
	<DT></DT>
	<DD><B>3. </B>Place the IMPLEMENT_SERIAL() macro in the class implementation.
	<P>
	<DT></DT>
	<DD><B>4. </B>Override the Serialize() function in the class.
	<P>
	<DT></DT>
	<DD><B>5. </B>Provide an empty, default constructor for the class.
	<P>
</DL>

<P>In the following section, you build an application that creates persistent objects
in just this way.</P>
<P>
<H3><A NAME="Heading6"></A>The File Demo 2 Application</H3>
<P>The next sample application, File Demo 2, demonstrates the steps you take to create
a class from which you can create persistent objects. It will have an Edit, Change
Messages command that changes all three strings. Like File Demo, it will save and
reload the document when the user chooses File, Save or File, Open.</P>
<P>Build an SDI application called MultiString just as you built File Demo. Add a
member variable to the document, as before, so that the Attributes section of MultiStringDoc.h
reads</P>
<P>
<PRE>// Attributes
public:
    CMessages m_messages;
</PRE>
<P>The next step is to write the CMessages class.</P>
<P>
<H3><A NAME="Heading7"></A>Looking at the CMessages Class</H3>
<P>Before you can understand how the document class manages to save and load its
contents successfully, you have to understand how the CMessages class, of which the
document class's m_messages data member is an object, works. As you work with this
class, you will see how to implement the preceding five steps for creating a persistent
class.</P>
<P>To create the CMessages class, first choose Insert, New Class. Change the class
type to generic class and name it <B>CMessages</B>. In the area at the bottom of
the screen, enter <B>CObject</B> as the base class name and leave the As column set
to public, as shown in Figure 7.3.</P>
<P><A HREF="javascript:popUp('07uvc03.gif')"><B>FIG. 7.3</B></A><B> </B><I>Create
a new class to hold the messages.</I></P>
<P>This will create two files: messages.h for the header and messages.cpp for the
code. It also adds some very simple code to these files for you. (You may get a warning
about not being able to find the header file for CObject: just click OK and ignore
it because CObject, like all MFC files, is available to you without including extra
headers.)</P>
<P>Switch back to Multistringdoc.h and add this line before the class definition:</P>
<P>
<PRE>#include &quot;Messages.h&quot;
</PRE>
<P>This will ensure the compiler knows about the CMessages class when it compiles
the document class. You can build the project now if you want to be sure you haven't
forgotten anything. Now switch back to Messages.h and add these lines:</P>
<P>
<PRE>    DECLARE_SERIAL(CMessages)
protected:
    CString m_message1;
    CString m_message2;
    CString m_message3;
public:
    void SetMessage(UINT msgNum, CString msg);
    CString GetMessage(UINT msgNum);
    void Serialize(CArchive&amp; ar);
</PRE>
<P>The DECLARE_SERIAL() macro provides the additional function and member variable
declarations needed to implement object persistence.</P>
<P>Next come the class's data members, which are three objects of the CString class.
Notice that they are protected member variables. The public member functions are
next. SetMessage(), whose arguments are the index of the string to set and the string's
new value, changes a data member. GetMessage() is the complementary function, enabling
a program to retrieve the current value of any of the strings. Its single argument
is the number of the string to retrieve.</P>
<P>Finally, the class overrides the Serialize() function, where all the data saving
and loading takes place. The Serialize() function is the heart of a persistent object,
with each persistent class implementing it in a different way. Listing 7.6 shows
the code for each of these new member functions. Add it to messages.cpp.</P>
<P>
<H4>Listing 7.6&#160;&#160;MESSAGES.CPP--The CMessages Class Implementation File</H4>
<PRE>void CMessages::SetMessage(UINT msgNum, CString msg)
{
     switch (msgNum)
     {
     case 1:
          m_message1 = msg;
          break;
     case 2:
        m_message2 = msg;
          break;
     case 3:
        m_message3 = msg;
          break;
     }
   SetModifiedFlag();
}
CString CMessages::GetMessage(UINT msgNum)
{
   switch (msgNum)
   {
      case 1:
         return m_message1;
      case 2:
         return m_message2;
      case 3:
         return m_message3;
      default:
         return &quot;&quot;;
   }
}
void CMessages::Serialize(CArchive&amp; ar)
{
    CObject::Serialize(ar);
    if (ar.IsStoring())
    {
        ar &lt;&lt; m_message1 &lt;&lt; m_message2 &lt;&lt; m_message3;
    }
    else
    {
        ar &gt;&gt; m_message1 &gt;&gt; m_message2 &gt;&gt; m_message3;
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩影视精品| 欧美sm美女调教| 99久久免费视频.com| 国产东北露脸精品视频| 国内精品伊人久久久久影院对白| 青青草原综合久久大伊人精品优势| 亚洲一二三四区| 午夜精品在线视频一区| 日韩国产成人精品| 麻豆精品新av中文字幕| 黄一区二区三区| 成人午夜大片免费观看| 95精品视频在线| 欧美日韩视频在线第一区| 欧美另类z0zxhd电影| 欧美一区二区黄| 久久老女人爱爱| 一区二区日韩av| 日本成人在线电影网| 精品在线一区二区| 99国产精品国产精品毛片| 欧美日韩三级一区| 久久人人超碰精品| 日韩美女视频19| 久久99久久久欧美国产| 成人高清视频在线观看| 欧美日韩黄色一区二区| 精品国产一区二区精华| 亚洲少妇30p| 久久不见久久见免费视频7| 94-欧美-setu| 久久综合网色—综合色88| 亚洲天堂免费看| 国产在线播放一区三区四| 99国产精品久| 久久久亚洲综合| 日韩国产高清影视| 色偷偷88欧美精品久久久| 日韩欧美黄色影院| 亚洲一区二区av在线| 国产一区二区看久久| 精品视频在线免费看| 久久精品一区二区三区av| 午夜激情久久久| 91啪亚洲精品| 久久久不卡网国产精品一区| 午夜精品福利一区二区三区av | 一区二区三区免费观看| 免费成人av资源网| 欧美伊人久久久久久久久影院 | 亚洲h动漫在线| 99久久久精品免费观看国产蜜| 欧美一区二区在线看| 亚洲综合色婷婷| av一区二区三区| 日本一区二区三区国色天香| 美美哒免费高清在线观看视频一区二区| av激情综合网| 国产精品毛片久久久久久久| 精品无人码麻豆乱码1区2区| 欧美乱熟臀69xxxxxx| 亚洲成a人片在线观看中文| 色综合久久久久久久久久久| 欧美激情综合网| 国产乱淫av一区二区三区| 日韩区在线观看| 久久成人麻豆午夜电影| 欧美zozozo| 激情文学综合网| 精品日韩一区二区三区| 狠狠色丁香婷综合久久| 日韩欧美国产1| 久久国产视频网| 久久精品一区二区三区四区| 国产精品综合视频| 久久精品视频在线免费观看 | 亚洲国产成人va在线观看天堂| hitomi一区二区三区精品| 中文字幕av免费专区久久| 成人午夜电影小说| 亚洲天堂成人网| 精品视频一区二区不卡| 亚洲成av人在线观看| 91精品国产综合久久香蕉的特点| 天堂成人国产精品一区| 日韩欧美不卡在线观看视频| 久久 天天综合| 国产色综合久久| 9人人澡人人爽人人精品| 亚洲激情图片qvod| 51精品秘密在线观看| 麻豆国产精品一区二区三区 | 1区2区3区精品视频| 色天使久久综合网天天| 午夜精品123| 久久视频一区二区| 成人高清在线视频| 香蕉久久一区二区不卡无毒影院| 欧美精品三级日韩久久| 韩国女主播成人在线| 亚洲人成在线观看一区二区| 欧美日韩卡一卡二| 国产综合一区二区| 一区二区成人在线观看| 日韩免费观看2025年上映的电影| 国内外成人在线| 一区二区三区产品免费精品久久75| 91精品国产91久久综合桃花| 国产做a爰片久久毛片| 一二三区精品视频| 久久久91精品国产一区二区三区| 色综合久久久久综合体 | 国产清纯白嫩初高生在线观看91| 91福利国产成人精品照片| 久久精品二区亚洲w码| 日本一区二区成人在线| 欧美人与z0zoxxxx视频| 成人性生交大片免费看视频在线| 亚洲高清免费一级二级三级| 国产精品视频第一区| 日韩欧美精品在线视频| 欧美亚洲高清一区| 99久久久精品免费观看国产蜜| 老司机精品视频导航| 亚洲一线二线三线视频| 中文一区一区三区高中清不卡| 91麻豆精品国产91久久久| 99久久国产综合色|国产精品| 美脚の诱脚舐め脚责91| 图片区日韩欧美亚洲| 亚洲精品中文在线影院| 中文字幕精品在线不卡| 精品国产乱码久久久久久久久| 911精品产国品一二三产区| 99国产精品国产精品毛片| 国产成人精品在线看| 国产一区二区三区国产| 另类综合日韩欧美亚洲| 亚洲一区二区五区| 亚洲黄色免费网站| 一区二区三区鲁丝不卡| 日韩毛片在线免费观看| 国产精品国产三级国产aⅴ原创| 欧美精品一区二区三区在线播放 | 久久在线免费观看| 欧美mv日韩mv国产| 日韩丝袜美女视频| 日韩一区二区在线看| 青青国产91久久久久久| 一区二区欧美精品| 亚洲日本护士毛茸茸| 亚洲欧美另类小说视频| 亚洲色图19p| 亚洲综合一二三区| 亚洲成人综合在线| 午夜精品久久久久久不卡8050| 午夜视频在线观看一区二区| 亚洲香蕉伊在人在线观| 偷偷要91色婷婷| 久久99国产精品久久99果冻传媒| 久久成人久久爱| 国产成人夜色高潮福利影视| 成人午夜电影小说| 色噜噜狠狠一区二区三区果冻| 色婷婷av一区二区三区gif| 色欧美片视频在线观看在线视频| 在线观看视频一区| 欧美一区二区视频免费观看| 久久综合av免费| 国产精品成人免费精品自在线观看 | 午夜久久久影院| 秋霞电影一区二区| 国产99久久精品| 欧美丝袜丝交足nylons| 日韩一区二区免费在线观看| 久久精品夜色噜噜亚洲aⅴ| 亚洲欧美在线观看| 亚洲成在人线在线播放| 国产精品一区二区三区99| 成人激情开心网| 欧美日精品一区视频| 亚洲精品一区在线观看| 一区二区三区国产豹纹内裤在线| 免费的成人av| 91视视频在线观看入口直接观看www | 亚洲欧美在线视频| 日韩va欧美va亚洲va久久| 成人手机在线视频| 欧美伦理电影网| 国产精品国产三级国产aⅴ无密码| 亚洲自拍偷拍九九九| 国产一区二区三区蝌蚪| 在线观看一区不卡| 国产亚洲成av人在线观看导航| 亚洲精品国产a| 国产不卡在线视频| 日韩亚洲欧美一区二区三区| 亚洲色图视频免费播放| 国产一区91精品张津瑜| 欧美日韩精品三区|