亚洲欧美第一页_禁久久精品乱码_粉嫩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亚洲国产成人精品一区二三| 天天影视涩香欲综合网| 亚洲chinese男男1069| 丝袜亚洲精品中文字幕一区| 麻豆91在线观看| 成人激情校园春色| 91精品福利视频| 精品av久久707| 亚洲欧美在线另类| 蜜臀久久99精品久久久久久9| 国产麻豆欧美日韩一区| 一本一道久久a久久精品| 欧美精品一二三| 国产亚洲精品7777| 亚洲综合激情网| 国产一区二区0| 日韩一级精品视频在线观看| 国产日韩三级在线| 久久草av在线| 欧美高清dvd| 亚洲视频免费在线观看| 久久久777精品电影网影网| 精品av久久707| 亚洲va天堂va国产va久| 色婷婷av一区| 欧美精彩视频一区二区三区| 激情六月婷婷久久| 欧美精品xxxxbbbb| 午夜激情久久久| 91久久精品一区二区二区| 亚洲欧洲国产日本综合| av动漫一区二区| 亚洲欧洲日本在线| 91麻豆免费看片| 中文字幕欧美区| 波多野结衣在线aⅴ中文字幕不卡| 日韩视频免费直播| 久久精工是国产品牌吗| 日韩一区二区精品在线观看| 日本亚洲免费观看| 欧美精品一区二区久久婷婷| 国产一区二区三区电影在线观看| www国产成人| 成人激情av网| 同产精品九九九| 精品区一区二区| av资源站一区| 性久久久久久久久久久久| 欧美日韩二区三区| 国产在线麻豆精品观看| 国产精品久久久久久久久搜平片| 丁香六月综合激情| 亚洲高清久久久| 久久这里只有精品视频网| 色综合久久久网| 精品一区二区在线免费观看| 亚洲欧美日韩国产中文在线| 欧美一区日韩一区| 99久久免费精品| 国产美女在线观看一区| 亚洲国产欧美在线| 亚洲天堂精品在线观看| 欧美一级xxx| 欧美色综合久久| www.欧美亚洲| 国产酒店精品激情| 午夜精品久久久久久久久久| 一区在线播放视频| 日本一区免费视频| 国产亚洲va综合人人澡精品| 欧美一级午夜免费电影| 欧美区在线观看| 欧美精品v日韩精品v韩国精品v| 99久久伊人网影院| 99re免费视频精品全部| 不卡一区中文字幕| 白白色 亚洲乱淫| 丰满少妇在线播放bd日韩电影| 久久精品国内一区二区三区| 免费观看30秒视频久久| 美女在线视频一区| 精品一区中文字幕| 国产在线观看一区二区| 国产91色综合久久免费分享| 国产99久久久久| 91网站在线观看视频| 欧美丰满高潮xxxx喷水动漫| 成人美女视频在线观看| 97久久超碰国产精品电影| 国产不卡在线视频| 欧美亚洲动漫制服丝袜| 欧美精品视频www在线观看| 欧美r级在线观看| 亚洲精品国产无天堂网2021 | 成人免费高清在线观看| 成人ar影院免费观看视频| 在线观看日韩毛片| 日韩美女主播在线视频一区二区三区| 久久色在线观看| 一区二区三区资源| 激情综合一区二区三区| 成人国产一区二区三区精品| 欧美日韩视频第一区| 久久亚洲捆绑美女| 亚洲成人免费影院| 成人av午夜电影| 久久天天做天天爱综合色| 一区二区三区美女| 国产69精品久久99不卡| 欧美浪妇xxxx高跟鞋交| 国产精品国产精品国产专区不蜜| 久久精品噜噜噜成人88aⅴ| 91久久精品国产91性色tv| 精品久久久久av影院| 亚洲欧美另类久久久精品2019| 国产精品99久久久久| 日本一区二区三区在线不卡| 国产一区二区三区四区在线观看 | 亚洲国产精华液网站w| 捆绑变态av一区二区三区| 欧美三级韩国三级日本一级| 亚洲欧洲日产国产综合网| 国产成人aaa| 中文字幕不卡在线播放| 成人精品亚洲人成在线| 国产精品美女久久久久久久网站| 韩国在线一区二区| 久久蜜桃香蕉精品一区二区三区| 久久66热re国产| 日韩一级成人av| 国产精品白丝jk黑袜喷水| 国产日韩av一区二区| 国产传媒欧美日韩成人| 中文字幕的久久| 91热门视频在线观看| 亚洲午夜一区二区三区| 精品女同一区二区| 国产美女精品在线| 亚洲视频香蕉人妖| 欧美视频一区二区在线观看| 天堂成人免费av电影一区| 欧美一卡2卡3卡4卡| 国产成人av电影在线| 日本在线播放一区二区三区| 在线不卡欧美精品一区二区三区| 美女视频一区二区| 中文字幕字幕中文在线中不卡视频| 欧美三级资源在线| 波波电影院一区二区三区| 天堂久久久久va久久久久| 国产色综合一区| 欧美一区二区三区啪啪| 91丨porny丨国产| 国产一区二区免费视频| 视频在线观看91| 国产精品乱码妇女bbbb| 欧美日韩电影一区| 成人app在线| 成人午夜免费电影| 国精产品一区一区三区mba视频| 亚洲日本成人在线观看| 国产日韩欧美一区二区三区乱码 | 亚洲第一综合色| 亚洲三级视频在线观看| 中文av一区二区| 中文字幕一区二区视频| 国产调教视频一区| 国产欧美日韩三区| 国产女主播一区| 中文字幕亚洲精品在线观看| 国产喷白浆一区二区三区| 日韩一区二区免费电影| 欧美v国产在线一区二区三区| 一级女性全黄久久生活片免费| 欧美视频第二页| 色婷婷久久久久swag精品| 成人黄色免费短视频| 国产精品一区二区在线播放| 激情综合色综合久久| 麻豆91小视频| 国产精品99久| 成人av免费在线观看| 丰满少妇久久久久久久| 欧美亚洲综合一区| 日韩视频在线永久播放| 91精品国产色综合久久久蜜香臀| 91精品国产综合久久久蜜臀图片| 欧美特级限制片免费在线观看| 欧美日韩视频一区二区| 欧美精品九九99久久| 久久久精品国产免大香伊| 亚洲精品综合在线| 亚洲电影在线播放| 激情文学综合网| 91网站最新地址| 欧美三级视频在线播放| 日韩欧美精品三级| 亚洲第一狼人社区| 卡一卡二国产精品|