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

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

?? ch08.htm

?? 24小時精通VC
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<BLOCKQUOTE>
	<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>Time Saver:</B></FONT><B> </B>It's important to
	remember that the <TT>DECLARE</TT> and <TT>IMPLEMENT</TT> macros are used in two
	different places. A<TT> DECLARE</TT> macro, such as <TT>DECLARE_DYNCREATE</TT>, is
	used in the class declaration. An <TT>IMPLEMENT</TT> macro, such as <TT>IMPLEMENT_DYNCREATE</TT>,
	is used only in the class definition. 
<HR>


</BLOCKQUOTE>

<H4><FONT COLOR="#000077">Creating an Object at Runtime</FONT></H4>
<P>There are two ways to create objects dynamically. The first method uses the C++
operator <TT>new</TT> to dynamically allocate an object from free storage.</P>
<PRE><FONT COLOR="#0066FF"><TT>CMyObject* pObject = new CMyObject;</TT>
</FONT></PRE>
<P>The second method is used primarily by the MFC framework and uses a special class,
<TT>CRuntimeClass</TT>, and the <TT>RUNTIME_CLASS</TT> macro. You can use <TT>CRuntimeClass</TT>
to determine the type of an object or to create a new object. Listing 8.9 creates
a <TT>CMyObject</TT> instance using the <TT>CRuntimeClass::CreateObject</TT> function.
<H4><FONT COLOR="#000077">TYPE: Listing 8.9. Creating an object at runtime using
CRuntimeClass.</FONT></H4>
<PRE><FONT COLOR="#0066FF"><TT>#include &lt;afx.h&gt;</TT>
<TT>#include &lt;iostream.h&gt;</TT>
<TT>#include &quot;MyObj.h&quot;</TT>
<TT>int main()</TT>
<TT>{</TT>
<TT>    CRuntimeClass* pRuntime = RUNTIME_CLASS( CMyObject );</TT>
<TT>    CObject* pObj = pRuntime-&gt;CreateObject();</TT>
<TT>    ASSERT( pObj-&gt;IsKindOf(RUNTIME_CLASS(CMyObject)) );</TT>

<TT>    CMyObject* pFoo = (CMyObject*)pObj;</TT>
<TT>    pFoo-&gt;Set( &quot;FooBar&quot; );</TT>

<TT>    cout &lt;&lt; pFoo-&gt;Get() &lt;&lt; endl;</TT>

<TT>    delete pFoo;</TT>
<TT>    return 0;</TT>
</FONT></PRE>
<P><TT>}</TT> Save the contents of Listing 8.9 as <TT>Runtime.cpp</TT> and add the
file to the Runtime project. Compile the project and if there are no errors, run
the project in a DOS window by following these steps:

<DL>
	<DD>1. Open a DOS window from the Start button's Programs menu.<BR>
	<BR>
	2. Change the current directory to the project directory.<BR>
	<BR>
	3. Type <TT>Debug\Runtime</TT> in the DOS window. The program executes and outputs
	<TT>FooBar</TT>.
</DL>

<P>Leave the DOS window open for now because you use it for the next example.
<H4><FONT COLOR="#000077">Testing for a Valid Object</FONT></H4>
<P>The MFC class library offers several diagnostic features. Most of these features
are in the form of macros that are used only in a debug version of your program.
This gives you the best of both worlds. When you are developing and testing your
program, you can use the MFC diagnostic functions to help ensure that your program
has as few errors as possible, although it runs with the additional overhead required
by the diagnostics. Later, when your program is compiled in a release version, the
diagnostic checks are removed and your program executes at top speed.</P>
<P>Three macros are commonly used in an MFC program:

<UL>
	<LI><TT>ASSERT</TT> brings up an error message dialog box when an expression that
	evaluates to <TT>FALSE</TT> is passed to it. This macro is compiled only in debug
	builds.<BR>
	<BR>
	
	<LI><TT>VERIFY</TT> works exactly like <TT>ASSERT</TT> except that the evaluated
	expression is always compiled, even for non-debug builds, although the expression
	is not tested in release builds.<BR>
	<BR>
	
	<LI><TT>ASSERT_VALID</TT> tests a pointer to a <TT>CObject</TT> instance and verifies
	that the object is a valid pointer in a valid state. A class derived from <TT>CObject</TT>
	can override the <TT>AssertValid</TT> function to enable testing of the state of
	an object.
</UL>

<P>The <TT>ASSERT</TT> and <TT>VERIFY</TT> macros are used with all expressions,
not just those involving <TT>CObject</TT>. Although they both test to make sure that
the evaluated expression is <TT>TRUE</TT>, there is an important difference in the
way these two macros work. When compiled for a release build, the <TT>ASSERT</TT>
macro and the expression it evaluates are completely ignored during compilation.
The <TT>VERIFY</TT> macro is also ignored, but the expression is compiled and used
in the release build.


<BLOCKQUOTE>
	<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>CAUTION:</B></FONT><B> </B>A common source of errors
	in MFC programs is placing important code inside an <TT>ASSERT</TT> macro instead
	of a <TT>VERIFY</TT> macro. If the expression is needed for the program to work correctly,
	it belongs in a <TT>VERIFY</TT> macro, not an <TT>ASSERT</TT> macro. These functions
	are used in examples throughout the rest of the book to test for error conditions.
	
<HR>


</BLOCKQUOTE>

<H4><FONT COLOR="#000077">Providing a Dump Function</FONT></H4>
<P>In addition to the diagnostic functions and macros in the previous section, <TT>CObject</TT>
declares a virtual function for displaying the contents of an object at runtime.
This function, <TT>Dump</TT>, is used to send messages about the current state of
the object to a debug window.</P>
<P>If you are debugging an MFC program, the messages are displayed in an output window
of the debugger. Add the source code from Listing 8.10 to the <TT>CMyObject</TT>
class declaration. The <TT>Dump</TT> function is usually placed in the implementation
section of the class declaration; in this example, it should be placed after the
declaration for <TT>m_szName</TT>. Because <TT>Dump</TT> is called only by the MFC
framework, it is usually declared as <TT>protected</TT> or <TT>private</TT>. Because
the <TT>Dump</TT> function is called only for debug builds, the declaration is surrounded
by <TT>#ifdef</TT> and <TT>#endif</TT> statements that remove the declaration for
<TT>Dump</TT> for release builds.
<H4><FONT COLOR="#000077">TYPE: Listing 8.10. Adding a Dump function to the CMyObject
declaration.</FONT></H4>
<PRE><FONT COLOR="#0066FF"><TT>#ifdef _DEBUG</TT>
<TT>    void Dump( CDumpContext&amp; dc ) const;</TT>
</FONT></PRE>
<P><TT>#endif</TT> Add the source code from Listing 8.11 to the <TT>MyObj.cpp</TT>
source code file. The implementation of the function is also bracketed by <TT>#ifdef</TT>
and <TT>#endif</TT> statements to remove the function for release builds.
<H4><FONT COLOR="#000077">TYPE: Listing 8.11. Adding the implementation of Dump to
CMyObject.</FONT></H4>
<PRE><FONT COLOR="#0066FF"><TT>#ifdef _DEBUG</TT>
<TT>void CMyObject::Dump( CDumpContext&amp; dc ) const</TT>
<TT>{</TT>
<TT>    CObject::Dump( dc );</TT>
<TT>    dc &lt;&lt; m_szName;</TT>
<TT>}</TT>
</FONT></PRE>
<P><TT>#endif</TT> The <TT>Dump</TT> function in Listing 8.11 calls the base class
version of <TT>Dump</TT> first. This step is recommended to get a consistent output
in the debug window. After calling <TT>CObject::Dump</TT>, member data contained
in the class is sent to the dump context using the insertion operator, <TT>&lt;&lt;</TT>,
just as if the data was sent to <TT>cout</TT>.
<H2><FONT COLOR="#000077"><B>Summary</B></FONT></H2>
<P>In this hour, you looked at how messages are handled by a program written for
Windows, and you wrote a sample program that handles and displays some commonly used
mouse event messages. You also looked at the <TT>CObject</TT> and <TT>CWnd</TT> base
classes and learned how to add diagnostic features to your classes.
<H2><FONT COLOR="#000077"><B>Q&amp;A</B></FONT></H2>

<DL>
	<DD><B>Q I want to have runtime class identification support for my class, and I
	also want to be able to create objects dynamically. I tried using the <TT>DECLARE_DYNAMIC</TT>
	and <TT>DECLARE_DYNCREATE</TT> macros together in my header file and the <TT>IMPLEMENT_DYNAMIC</TT>
	and <TT>IMPLEMENT_DYNCREATE</TT> macros in my source file, but I got lots of errors.
	What happened?</B><BR>
	<BR>
	<B>A</B> The macros are cumulative; The <TT>xxx_DYNCREATE</TT> macros also include
	work done by the <TT>xxx_DYNAMIC</TT> macros. The <TT>xxx_SERIAL</TT> macros also
	include <TT>xxx_DYNCREATE</TT>. You must use only one set of macros for your application.<BR>
	<BR>
	<B>Q Why does the MouseTst program go to the trouble of invalidating part of the
	view, then updating the window in <TT>OnDraw</TT>? Wouldn't it be easier to just
	draw directly on the screen when a mouse click is received?</B><BR>
	<BR>
	<B>A</B> When the MouseTst window is overlapped by another window then uncovered,
	the view must redraw itself; this code will be located in <TT>OnDraw</TT>. It's much
	easier to use this code in the general case to update the display rather than try
	to draw the output in multiple places in the source code.
</DL>

<H2><FONT COLOR="#000077"><B>Workshop</B></FONT></H2>
<P>The Workshop is designed to help you anticipate possible questions, review what
you'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 default window procedure?<BR>
	<BR>
	2. Why are messages used to pass information in Windows programs?<BR>
	<BR>
	3. How is an application notified that the mouse is passing over one of its windows?<BR>
	<BR>
	4. What is a message map used for?<BR>
	<BR>
	5. What is the base class for most MFC classes?<BR>
	<BR>
	6. What is the <TT>CObject::Dump</TT> function used for?<BR>
	<BR>
	7. What is the difference between the <TT>ASSERT</TT> and <TT>VERIFY</TT> macros?<BR>
	<BR>
	8. What message is sent to an application when the user presses the primary mouse
	button?<BR>
	<BR>
	9. How can you determine which source code lines in a message map are reserved for
	use by ClassWizard?
</DL>

<H3><FONT COLOR="#000077"><B>Exercises</B></FONT></H3>

<DL>
	<DD>1. Modify the MouseTst program to display the current mouse position as the mouse
	is moved over the view.<BR>
	<BR>
	2. Add an <TT>ASSERT</TT> macro to ensure that <TT>pObj</TT> is not <TT>NULL</TT>
	after it is created in <TT>Runtime.cpp</TT>.<FONT COLOR="#000077"></FONT>
</DL>

<CENTER>
<P>
<HR>
<A HREF="ch07.htm" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/ch07/ch07.htm"><IMG SRC="previous.gif" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="ch09.htm" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/ch09/ch09.htm"><IMG
SRC="next.gif" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="index-1.htm" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/index.htm"><IMG SRC="contents.gif" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR>
<BR>
<BR>
<IMG SRC="corp.gif" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/button/corp.gif" WIDTH="284" HEIGHT="45" ALIGN="BOTTOM" ALT="Macmillan Computer Publishing USA"
BORDER="0"></P>

<P>&#169; <A HREF="copy.htm" tppabs="http://www.mcp.com/824169600/0-672/0-672-31242-5/copy.htm">Copyright</A>, Macmillan Computer Publishing. All
rights reserved.
</CENTER>


</BODY>

</HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
高清国产一区二区| 日韩精品中文字幕在线一区| 麻豆高清免费国产一区| 美女网站色91| 91在线云播放| 精品国产一区二区三区忘忧草| 自拍偷拍欧美精品| 国产一区二区免费看| 欧美日韩一区视频| 亚洲天堂精品视频| 国产成人av一区二区三区在线观看| 欧美视频一区二区三区四区| 国产精品电影一区二区| 国精产品一区一区三区mba视频 | 91精品黄色片免费大全| 一区在线播放视频| 极品少妇xxxx精品少妇| 91精品国产综合久久福利| 亚洲乱码中文字幕| 成人精品国产免费网站| 欧美高清在线精品一区| 国产经典欧美精品| 欧美精品一区二区不卡| 久久精品99国产精品日本| 91精品国产高清一区二区三区| 亚洲第一成人在线| 欧美日韩一级片在线观看| 亚洲成人福利片| 欧美日韩国产高清一区二区 | 国产视频一区二区在线观看| 久久99精品久久久久婷婷| 欧美一区二区三区日韩视频| 日韩中文字幕av电影| 777欧美精品| 奇米精品一区二区三区在线观看| 欧美高清性hdvideosex| 午夜精品爽啪视频| 欧美日韩小视频| 亚洲欧美成人一区二区三区| 欧美专区在线观看一区| 国产精品成人午夜| 成人免费毛片片v| 国产亚洲欧美激情| 国产精品一区二区在线观看不卡| 欧美一二三在线| 久久精品免费看| 欧美一级黄色大片| 蜜臀久久久99精品久久久久久| 91福利在线播放| 在线播放欧美女士性生活| 日韩电影一区二区三区四区| 91国偷自产一区二区三区观看| 中文字幕第一页久久| 国产成人免费视频精品含羞草妖精| 26uuu国产在线精品一区二区| 日本欧美肥老太交大片| 日韩精品一区二区三区视频| 激情都市一区二区| 久久久久久99久久久精品网站| 国产精品一区二区不卡| 中文字幕久久午夜不卡| av网站免费线看精品| 亚洲欧美日韩在线| 欧美性大战久久久久久久| 日韩电影免费一区| 精品国精品国产尤物美女| 精品伊人久久久久7777人| 国产精品免费看片| 色综合天天综合在线视频| 亚洲一级在线观看| 色综合久久综合网欧美综合网 | 成人在线综合网站| 一卡二卡欧美日韩| 7777精品伊人久久久大香线蕉的 | 日韩欧美亚洲国产精品字幕久久久| 蜜桃av噜噜一区| 国产欧美日韩综合精品一区二区| 成人在线一区二区三区| 亚洲国产一区二区三区| 日韩欧美国产wwwww| 国产成人精品免费一区二区| 国产精品国产a| 成人网男人的天堂| 偷拍日韩校园综合在线| 精品国产伦一区二区三区观看体验| 国产91精品一区二区| 亚洲3atv精品一区二区三区| 久久你懂得1024| 欧美性一二三区| 国产在线日韩欧美| 一区二区三区四区在线免费观看| 日韩一区二区中文字幕| 成人午夜私人影院| 偷窥国产亚洲免费视频| 久久久综合精品| 色久优优欧美色久优优| 美国毛片一区二区三区| 自拍视频在线观看一区二区| 欧美一区二区成人6969| av亚洲精华国产精华精华 | 成人精品鲁一区一区二区| 热久久免费视频| 亚洲欧美偷拍卡通变态| 久久精品人人做人人综合| 欧美精品乱码久久久久久 | 国产一二三精品| 亚洲一区成人在线| 亚洲日本乱码在线观看| 亚洲精品一区二区三区在线观看 | 色婷婷综合久色| 国产一区二区三区不卡在线观看 | 成人永久看片免费视频天堂| 五月综合激情日本mⅴ| 亚洲欧美区自拍先锋| 精品国产免费人成在线观看| 91黄色免费看| 成人高清免费在线播放| 亚洲动漫第一页| 国产精品日产欧美久久久久| 精品理论电影在线观看| 欧美一级理论片| 7777女厕盗摄久久久| 91麻豆免费观看| 99精品在线观看视频| 成人一区在线看| 国产盗摄一区二区| 国产在线播放一区二区三区| 蜜乳av一区二区三区| 午夜精品久久久| 国产精品欧美精品| 91精品国产91久久久久久一区二区| 91精品国产免费| 91福利精品第一导航| 欧美亚洲日本一区| 欧美性xxxxxxxx| 欧美男女性生活在线直播观看| 日本精品一级二级| 欧美日韩亚洲高清一区二区| 欧美性一级生活| 4438成人网| 欧美xxxxx牲另类人与| 欧美成人精品福利| 欧美成人精品1314www| 欧美成人国产一区二区| 久久综合久色欧美综合狠狠| 2020国产精品| 国产日韩视频一区二区三区| 亚洲国产精品成人综合| 日韩精品一区二区三区视频| 欧美韩国日本一区| 亚洲欧美综合色| 亚洲一区二区在线播放相泽 | 国产成人在线视频网址| 国产 欧美在线| 欧美在线高清视频| 日韩女优av电影在线观看| 久久久91精品国产一区二区精品| 国产女同性恋一区二区| 亚洲激情图片qvod| 日韩电影在线一区| 成人影视亚洲图片在线| 欧美在线免费视屏| 欧美精品一区二区高清在线观看 | 成人av电影在线观看| 欧美视频一区二区在线观看| 日韩美一区二区三区| 亚洲国产激情av| 亚洲国产你懂的| 国产一区二区三区最好精华液| 国产精品18久久久| 国产乱码精品一区二区三区av| 欧美日韩aaaaaa| 国产精品人妖ts系列视频| 性做久久久久久| 国产成都精品91一区二区三| 91久久香蕉国产日韩欧美9色| 欧美xfplay| 一区二区三区精品久久久| 激情综合色播五月| 欧美体内she精视频| 国产欧美日韩另类视频免费观看| 亚洲精品成人悠悠色影视| 国内精品第一页| 欧美日韩色一区| 国产精品丝袜久久久久久app| 日韩av一二三| 91欧美激情一区二区三区成人| 欧美一卡2卡3卡4卡| 国产精品高潮呻吟| 极品少妇xxxx精品少妇偷拍| 欧美色手机在线观看| 中文字幕的久久| 蜜桃视频免费观看一区| 欧美一区二区三区色| 亚洲一区二区视频| av亚洲精华国产精华精华| 国产丝袜在线精品| 蜜臂av日日欢夜夜爽一区| 欧美喷水一区二区| 亚洲成人第一页|