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

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

?? ch08.htm

?? 一天之內學會VC#. 主要介紹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一区二区三区免费野_久草精品视频
色婷婷国产精品| 中文字幕日本不卡| 国产精品视频你懂的| 亚洲国产毛片aaaaa无费看 | 69堂成人精品免费视频| 欧美国产综合一区二区| 国产成人精品一区二区三区四区| 91麻豆产精品久久久久久| 日韩欧美高清一区| 亚洲国产日韩a在线播放性色| 国产精品综合一区二区三区| 欧美久久免费观看| 亚洲精品高清在线观看| 成人免费的视频| 久久综合网色—综合色88| 秋霞影院一区二区| 91丝袜高跟美女视频| 国产精品乱人伦| 国产一区福利在线| 欧美一区二区三区喷汁尤物| 亚洲午夜视频在线观看| 色综合久久综合网欧美综合网| 国产肉丝袜一区二区| 久久99久久精品欧美| 91精品福利在线一区二区三区 | 一区二区三区四区蜜桃 | 国内精品嫩模私拍在线| 欧美一区二区三级| 日韩中文字幕区一区有砖一区 | 不卡在线观看av| 欧美国产日韩精品免费观看| 国产高清久久久久| 中文字幕欧美国产| 成人丝袜视频网| 国产精品免费视频网站| kk眼镜猥琐国模调教系列一区二区| 久久嫩草精品久久久久| 国产电影一区在线| 国产精品久久久久久久久免费樱桃 | 蜜桃视频一区二区三区在线观看| 欧美夫妻性生活| 青青草国产精品97视觉盛宴| 欧美一级免费观看| 国模冰冰炮一区二区| 国产欧美一区二区三区在线老狼| 成人免费观看视频| 日韩伦理电影网| 精品视频在线免费观看| 日韩精品一二三四| 久久毛片高清国产| 91小宝寻花一区二区三区| 免费观看成人av| 精品88久久久久88久久久| 国产成人免费在线观看不卡| 中文字幕一区二区在线播放| 色哟哟一区二区三区| 图片区小说区区亚洲影院| 精品日韩99亚洲| 成人福利电影精品一区二区在线观看| 亚洲欧美另类久久久精品| 精品视频免费看| 国内精品久久久久影院色| 国产精品情趣视频| 欧美日韩免费一区二区三区| 麻豆91在线观看| 国产精品国产成人国产三级 | 亚洲精品高清在线观看| 日韩欧美激情在线| 不卡的av电影| 奇米精品一区二区三区在线观看| 国产性天天综合网| 欧美日韩精品综合在线| 国产盗摄精品一区二区三区在线| 伊人夜夜躁av伊人久久| 亚洲精品一区二区在线观看| 色诱亚洲精品久久久久久| 免费精品视频最新在线| 亚洲天堂久久久久久久| 欧美mv日韩mv| 欧美自拍偷拍一区| 丁香五精品蜜臀久久久久99网站| 亚洲国产日韩av| 国产精品色眯眯| 日韩精品中文字幕在线一区| 色综合天天综合网天天狠天天| 另类成人小视频在线| 亚洲午夜久久久久久久久久久| 久久一二三国产| 69久久夜色精品国产69蝌蚪网| 91丨porny丨最新| 国产一区二区三区四区五区美女| 亚洲成人免费影院| 综合电影一区二区三区 | 中文字幕亚洲在| 久久综合色之久久综合| 欧美高清hd18日本| 一本到三区不卡视频| 国产高清成人在线| 99久久婷婷国产| 国产一区二区三区黄视频| 麻豆国产精品一区二区三区 | 欧美激情综合网| 欧美丰满嫩嫩电影| 色综合久久久久综合99| av在线播放一区二区三区| 国产精品91xxx| 国产一区视频导航| 激情欧美一区二区三区在线观看| 天堂一区二区在线免费观看| 亚洲国产精品一区二区尤物区| 亚洲精选一二三| 亚洲欧洲av另类| 日韩理论片在线| 亚洲欧美成人一区二区三区| 最好看的中文字幕久久| 亚洲色大成网站www久久九九| 国产精品嫩草影院av蜜臀| 中文字幕不卡在线播放| 中文字幕一区在线| 亚洲三级久久久| 亚洲午夜久久久久中文字幕久| 亚洲制服丝袜av| 一级精品视频在线观看宜春院| 一区二区三区在线观看动漫| 亚洲一卡二卡三卡四卡| 亚洲电影欧美电影有声小说| 日韩成人免费在线| 精品综合免费视频观看| 国产精品一区免费在线观看| 国产成人综合在线播放| 99久久夜色精品国产网站| 色婷婷综合久久久久中文| 欧美日韩成人综合在线一区二区| 久久久亚洲欧洲日产国码αv| 国产女人aaa级久久久级| 日韩一区在线播放| 五月婷婷激情综合| 九一九一国产精品| jizzjizzjizz欧美| 欧美性色综合网| 日韩欧美激情在线| 中文字幕五月欧美| 调教+趴+乳夹+国产+精品| 经典三级视频一区| 99国产精品国产精品久久| 6080亚洲精品一区二区| 久久精品人人做人人综合| 亚洲欧美日韩国产综合在线| 日日摸夜夜添夜夜添国产精品| 国产一区欧美二区| 91久久精品午夜一区二区| 日韩亚洲国产中文字幕欧美| 欧美国产日韩精品免费观看| 亚洲午夜在线观看视频在线| 国产一区二区三区在线观看免费 | 精品亚洲porn| 99久久er热在这里只有精品66| 欧美日韩一区二区三区在线看| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲欧美日韩在线| 国产伦精品一区二区三区在线观看| 日本久久电影网| 欧美大尺度电影在线| 亚洲视频免费看| 国产在线精品免费| 欧美日本一区二区在线观看| 欧美激情一区不卡| 蜜臀99久久精品久久久久久软件| 成人av网站在线观看| 日韩精品一区二区三区三区免费| 亚洲毛片av在线| 国产成人av在线影院| 91精品在线免费| 亚洲三级在线免费观看| 国产乱子伦视频一区二区三区| 欧美日韩国产欧美日美国产精品| 国产精品色婷婷| 国产中文字幕精品| 7777精品伊人久久久大香线蕉超级流畅 | 欧美电影一区二区| 亚洲国产成人tv| 99久久精品99国产精品| 久久综合色之久久综合| 免费成人结看片| 欧美午夜精品免费| 亚洲另类在线一区| av亚洲产国偷v产偷v自拍| 国产日韩欧美麻豆| 国产一区二区三区不卡在线观看 | 国产精品久久久久久妇女6080| 激情亚洲综合在线| 日韩欧美国产三级电影视频| 亚洲一二三专区| 欧美在线小视频| 亚洲影院免费观看| 一本色道久久综合狠狠躁的推荐| 中文字幕欧美一| 91网站最新地址| 亚洲精选一二三| 欧美午夜精品电影|