?? ape.htm
字號:
<TD ALIGN="LEFT">VERIFY</TD>
<TD ALIGN="LEFT">Like ASSERT, but VERIFY evaluates the ASSERT expression in both the debug and release
versions of MFC. If the assertion fails, a message is printed and the program is
halted only in the debug version.</TD>
</TR>
</TABLE>
<H2><A NAME="Heading7"></A>Exception Processing</H2>
<P><I>Exceptions</I> give a program greater control over how errors are handled (see
Chapter 26). Before exceptions were part of the language, MFC developers used macros
to achieve the same results. Now that exceptions are firmly established in Visual
C++, a number of functions make it easier to throw exceptions of various types. These
macros and functions are listed in Table E.7.</P>
<P>
<H4>Table E.7  Exception Macros and Functions</H4>
<P>
<TABLE BORDER="1">
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT"><B>Symbol</B></TD>
<TD ALIGN="LEFT"><B>Description</B></TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxAbort()</TD>
<TD ALIGN="LEFT">Terminates an application upon a fatal error</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowArchiveException()</TD>
<TD ALIGN="LEFT">Throws an archive exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowDAOException()</TD>
<TD ALIGN="LEFT">Throws a CDAOException</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowDBException()</TD>
<TD ALIGN="LEFT">Throws a CDBException</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowFileException()</TD>
<TD ALIGN="LEFT">Throws a file exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowMemoryException()</TD>
<TD ALIGN="LEFT">Throws a memory exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowNotSupportedException()</TD>
<TD ALIGN="LEFT">Throws a not-supported exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowOleDispatchException()</TD>
<TD ALIGN="LEFT">Throws an OLE automation exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowOleException()</TD>
<TD ALIGN="LEFT">Throws an OLE exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowResourceException()</TD>
<TD ALIGN="LEFT">Throws a resource-not-found exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AfxThrowUserException()</TD>
<TD ALIGN="LEFT">Throws an end user exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AND_CATCH</TD>
<TD ALIGN="LEFT">Begins code that will catch specified exceptions not caught in the preceding TRY
block</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">AND_CATCH_ALL</TD>
<TD ALIGN="LEFT">Begins code that will catch all exceptions not caught in the preceding TRY block</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">CATCH</TD>
<TD ALIGN="LEFT">Begins code for catching an exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">CATCH_ALL</TD>
<TD ALIGN="LEFT">Begins code for catching all exceptions</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">END_CATCH</TD>
<TD ALIGN="LEFT">Ends CATCH or AND_CATCH code blocks</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">END_CATCH_ALL</TD>
<TD ALIGN="LEFT">Ends CATCH_ALL code blocks</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">THROW</TD>
<TD ALIGN="LEFT">Throws a given exception</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">THROW_LAST</TD>
<TD ALIGN="LEFT">Throws the most recent exception to the next handler</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">TRY</TD>
<TD ALIGN="LEFT">Starts code that will accommodate exception handling</TD>
</TR>
</TABLE>
<H2><A NAME="Heading8"></A>Message-Map Macros</H2>
<P>Windows is an event-driven operating system, which means that every Windows application
must handle a flood of messages that flow between an application and the system.
MFC does away with the clunky switch statements that early Windows programmers had
to construct to handle messages and replaces those statements with a message map.
A <I>message map</I> is nothing more than a table that matches a message with its
message handler (see Chapter 3, "Messages and Commands"). To simplify the
declaration and definition of these tables, Visual C++ defines a set of message-map
macros. Many of these macros, which are listed in Table E.8, will already be familiar
to experienced MFC programmers.</P>
<P>
<H4>Table E.8  Message-Map Macros</H4>
<P>
<TABLE BORDER="1">
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT"><B>Macro</B></TD>
<TD ALIGN="LEFT"><B>Description</B></TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">BEGIN_MESSAGE_MAP</TD>
<TD ALIGN="LEFT">Begins a message-map definition</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">DECLARE_MESSAGE_MAP</TD>
<TD ALIGN="LEFT">Starts a message-map declaration</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">END_MESSAGE_MAP</TD>
<TD ALIGN="LEFT">Ends a message-map definition</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_COMMAND</TD>
<TD ALIGN="LEFT">Begins a command-message message-map entry</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_COMMAND_RANGE</TD>
<TD ALIGN="LEFT">Begins a command-message message-map entry that maps multiple messages to a single
handler</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_CONTROL</TD>
<TD ALIGN="LEFT">Begins a control-notification message-map entry</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_CONTROL_RANGE</TD>
<TD ALIGN="LEFT">Begins a control-notification message-map entry that maps multiple control IDs to
a single handler</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_MESSAGE</TD>
<TD ALIGN="LEFT">Begins a user-message message-map entry</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_REGISTERED_MESSAGE</TD>
<TD ALIGN="LEFT">Begins a registered user-message message-map entry</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_UPDATE_COMMAND_UI</TD>
<TD ALIGN="LEFT">Begins a command-update message-map entry</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">ON_UPDATE_COMMAND_UI_RANGE</TD>
<TD ALIGN="LEFT">Begins a command-update message-map entry that maps multiple command-update messages
to a single handler</TD>
</TR>
</TABLE>
<H2><A NAME="Heading9"></A>Runtime Object Model Services</H2>
<P>Frequently in your programs, you need access to information about classes at runtime.
MFC supplies a macro for obtaining this type of information in a CRuntimeClass structure.
In addition, the MFC application framework relies on a set of macros to declare and
define runtime abilities (such as object serialization and dynamic object creation).
If you've used AppWizard at all, you've seen these macros in the generated source-code
files. If you're an advanced MFC programmer, you might have even used these macros
yourself. Table E.9 lists the runtime macros and their descriptions.</P>
<P>
<H4>Table E.9  Runtime Services Macros</H4>
<P>
<TABLE BORDER="1">
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT"><B>Macro</B></TD>
<TD ALIGN="LEFT"><B>File</B></TD>
<TD ALIGN="LEFT"><B>Description</B></TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">DECLARE_DYNAMIC</TD>
<TD ALIGN="LEFT">Class declaration(.h)</TD>
<TD ALIGN="LEFT">Enables runtime class information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">DECLARE_DYNCREATE</TD>
<TD ALIGN="LEFT">Class declaration(.h)</TD>
<TD ALIGN="LEFT">Enables the class (derived from CObject) to be created dynamically and also enables
runtime class information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">DECLARE_OLECREATE</TD>
<TD ALIGN="LEFT">Class declaration (.h)</TD>
<TD ALIGN="LEFT">Enables object creation with OLE automation</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">DECLARE_SERIAL</TD>
<TD ALIGN="LEFT">Class declaration (.h)</TD>
<TD ALIGN="LEFT">Enables object serialization, as well as runtime class information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">IMPLEMENT_DYNAMIC</TD>
<TD ALIGN="LEFT">Class implementation (.cpp)</TD>
<TD ALIGN="LEFT">Enables runtime class information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">IMPLEMENT_DYNCREATE</TD>
<TD ALIGN="LEFT">Class implementation (.cpp)</TD>
<TD ALIGN="LEFT">Enables dynamic creation of the object and runtime information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">IMPLEMENT_OLECREATE</TD>
<TD ALIGN="LEFT">Class implementation (.cpp)</TD>
<TD ALIGN="LEFT">Enables object creation with OLE</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">IMPLEMENT_SERIAL</TD>
<TD ALIGN="LEFT">Class implementation (.cpp)</TD>
<TD ALIGN="LEFT">Enables object serialization and runtime class information access</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">RUNTIME_CLASS</TD>
<TD ALIGN="LEFT"></TD>
<TD ALIGN="LEFT">Returns a CRuntimeClass structure for the given class</TD>
</TR>
</TABLE>
<H2><A NAME="Heading10"></A>Standard Command and Window IDs</H2>
<P>A Windows application user can generate myriad standard messages. For example,
whenever the user selects a menu command from a standard menu like File or Edit,
the program sends a message. Each standard command is represented by an ID. To relieve
the programmer of having to define the dozens of IDs often used in a Windows application,
Visual C++ defines these symbols in a file called AFXRES.H. Some of these IDs have
obvious purposes (for example, ID_FILE_OPEN), but many others are used internally
by MFC for everything from mapping standard Windows messages to their handlers, to
defining string-table IDs, to assigning IDs to toolbar and status bar styles.</P>
<P>There are far too many of these identifiers to list here. However, if you're interested
in seeing them, just open the AFXRES.H file from your Visual C++ installation folder.</P>
<H1></H1>
<CENTER>
<P>
<HR>
<A HREF="../apd/apd.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../apf/apf.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> <BR>
</P>
<P>© <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. All
rights reserved.
</CENTER>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -