Meanings of commonly used Macros in Visual C ++ MFC

Source: Internet
Author: User

Meanings of commonly used Macros in Visual C ++ MFC
And_catchand_catch and_catch (exception_class, exception _ object_point_name) Description:
Define Code Block, which is used to obtain the additional exception type in the current try block. Use the catch macro to obtain an exception type, and then use the and_catch macro to obtain the subsequent exception handling code. You can access the exception object (if appropriate) and have more messages about the special cause of the exception. Call the throw_last macro in the and_catch block to move the processing process to the next External exception framework. And_catch can mark the end of the catch or and_catch block.
Note: The and_catch block is defined as a C ++ scope (described by curly brackets ). If you define variables in this scope, remember that they are only accessible in this scope. It is also used for the prediction_object_pointer_name variable.
Assert assert (booleanexpression) Description: calculates the value of a variable. If the value of the structure is 0, this macro prints a Diagnostic message and fails to run the message. If the condition is not 0, nothing will be done. The diagnosis message is in the form of assertion failed in file in line, where name is the object name, And num is the interrupt Number of the failed operation in the source file. In the release version, assert does not compute the expression value and does not interrupt Program . If the value of this expression must be calculated regardless of the environment, use verify instead of assert. Note: assert can only be used in debug
Assert_vaild (pobject) Description: used to check the validity of the internal state of an object. Assert_valid calls the assertvalid member functions of this object (pass them as their own variables ). In release, assert_valid does nothing. In the debug version, it checks pointers in a way different from null and calls the object's own assertvalid member function. If any of these checks fails, a warning message is displayed in the same way as assert. Note: This function is only valid in debug.
Begin_message_map (the class, baseclass) Description: Use begin_message_map to start the definition of user message ing. In the tool (. cpp) file that defines user-class functions, start message ing with begin_message_map macro, add macro items for each message processing function, and then use end_message_map macro to complete message ing.
Catch catch (exception_class, exception_object_pointer_name) Description: defines a code block. This code is used to obtain an exception type in the current try block. The exception handling code can access the exception object. If appropriate, you will receive more messages about the special causes of the exception. Call the throw_last macro to set the processing process as an external exception framework. If exception-class is a class c0000tioon, all Exception types are obtained. You can use the cobject: iskindof member function to confirm that the special exception is excluded. The best way to get exceptions is to use the sequential and_catch statement, each with a different exception type. The pointer to this exception type is defined by a macro, which is not required by the user. Note: This catch block is defined as a C ++ range (described in curly brackets ). If you define variables in this range, they can only be accessed within the eating range. It can also be used as a pointer to an exception object.
Debug_new # define new debug_new Description: helps you find memory errors. The user uses debug_new in the program. The user usually uses the new operator to allocate data from the stack. In debug mode (but a debug symbol is defined), debug_new records the file name and row number of each object assigned to it. Then, when you use the cmemorystate: dumpallobjectsince member function, the file name and row number are displayed for each object allocated with debug_new. To use debug_new, insert the following command in the user's resource file: # define new debug_new once the user inserts this command, the Preprocessing Program inserts debug_new where new is used, while MFC does the rest of the work. However, when you compile a release version of your program, debug_new performs a simple new operation without generating file name and row number messages.
Declare_dynamic (class_name) Description: When a class is derived from cobject, this macro adds the access runtime function for an object class. Add the declare_dynamic macro to the Class header file, and then include this module in all. cpp files that need to access part class objects. If delcare_dynamic and implement_dynamic macros are used as described, you can use the runtime_class macro and cobject: iskindof function to determine the object class during running time. If declare_dynamic is included in the class definition, implemetn_dynamic must be included in the class tool.
Declare_dyncreate (class_name) Description: Use the declare_dyncrete macro to allow the cobject derived class to automatically create objects at runtime. The host uses this function to automatically create new objects. For example, when it reads an object from the disk during serialization, the file, view, and frame window should support dynamic creation, because the framework needs to be automatically created. Add the declare_dyncreate macro to the. h file of the class, and then include this mode in the. cpp file that needs to access such objects. If declare_dyncreate is included in the class definition, implement_dyncreate must be included in the class tool.
Declare_message_map () Description: Each cve-target derived class in the user program must provide message ing to process messages. Use the declare_message_map macro at the end of the class definition. Next, use the begin_message_map macro in the. cpp file that defines the class member function, the list under the macro item of each user message processing function, and the end_message_map macro. NOTE: If any member is defined after declare_message_map, a new access type (public, private, and protected) must be specified for them ).
Declare_serial (class_name) Description: declare_serial generates the necessary C ++ title code for a serializable cobject derived class. Serialization refers to reading and writing the content of an object from a file. Use the declare_serial macro in the. h file, and then include the file in all. cpp files that need to access such objects. If declare_serial is included in the class definition, implement_serial must be included in the class tool. The declare_serial macro contains all the functions of declare_dynamic and implement_dycreate.
End_catch: Specifies the end of the final catch or and_catch block.
End_message_map Description: Use the end_message_map macro to end your message ing definition implement_dynamic (class_name, base_class_name) Description: the necessary C ++ code is generated by running the sequence class name and position of the dynamic cobject derived class in the serial structure. Use the implement_dynamic macro in the. cpp file, and then link the result object code
Implement_dyncreate (class_name, base_class_name) Description: Use the declare_dyncreate macro to use the implement_dyncreate macro to allow the cobject derived class object to be automatically created at runtime. The host uses this function to automatically create an object. For example, when it reads an object from the disk during serialization, it adds the implement_dyncreate macro to the class tool. If you use the declare_dyncreate and implement_dyncreate macros, use the runtime_class macro and cobject: iskindof member functions to determine the object class at runtime. If declare_dyncreate is included in the definition, implement_dyncreate must be included in the class tool.
Implement_serial (class_name, base_class_name, wschema) Description: You can use the dynamic cobject derived class name and position in the serial structure during runtime to create necessary C ++ code. Use the implement_serial macro in the. cpp file, and then link the result object code once.
On_command (ID, memberfxn) Description: This macro inserts a message ing by classwizard or manually. It indicates that the function will process a command message from a command User Interface (such as a menu item or toolbar button. When a command object receives a Windows wm_command message with the specified ID, on_command calls the member function memberfxn to process the message. In user message ing, there should be an on_command macro statement for each menu or accelerator command (which must be mapped to a message processing function.
On_control (wnotifycode, ID, memberfxn) Description: indicates which function will process a regular control to represent a message. Control identifies messages that are sent from a controller to the parent window.
On_message (message, memberfxn) Description: Specifies which function will process a user-defined message. User-defined messages are generally defined within the range of wm_user to 0x7ff. User-defined messages are any messages that are not standard Windows wm_message messages. In user message ing, each message must be mapped to a message processing function. A user-defined message should have an on_message macro statement.
On_registered_message (nmessagevarible, memberfxn) Description: The registerwindowsmesage function of Windows is used to define a new window message, which is always unique throughout the system. This macro indicates which function processes registered messages. The nmessageviable variable should be defined by the near modifier.
On_update_command_ui (ID, memberfxn) Description: This macro usually inserts a message ing through classwizard to indicate which function will process a user interface change command message. In the message ing of a user, each user interface change command (which is mapped to a message processing function) should have an on_update_command_ui macro statement.
On_vbxevent (wnotifycode, memberfxn) Description: This macro usually inserts a message ing through classwizard to indicate which function will process a message controlled by vbx. In message ing, each vbx Control Message mapped to a message processing function should have a macro statement.
Runtime_class (class_name) Description: This macro is used to obtain the class structure during runtime from the C ++ class. Runtime_class returns a pointer to the cruntimeclass structure for the class specified by class_name. Only cobject Derived classes defined by declare_dynamic, declare_dyncreate, or declare_serial can return a pointer to a cruntimeclass structure.
Throw throw (exception_object_pointer) indicates that the specified exception is sent. Throw interrupts the running of the program and passes the control to the Catch Block related to the user program. If a Catch Block is not provided, the control is passed to an MFC module, which prints an error and terminates the operation.
Throw_last () indicates that this macro allows the user to send a local build exception. If you try to exclude a detected exception, the exception will generally overflow and be deleted. Throw_last is used. This exception is directly transmitted to the next catch handler.
Trace trace (exp) Description: sends a formatted string to a dump device, for example, a file or debugging monitor, and provides functions similar to printf. Like printf of C program in ms_dos, trace macro is a convenient form of tracking variable values during program running. In the debug environment, the trace macro is output to afxdump. He does not do any work in release. Note: This macro is only valid in the debug version of MFC.
Trace0 trace0 (exp) Description: similar to trace, but it places the trace string in the code segment rather than dgroup, So it uses less dgroup space. Trace0 is a variant of a group of Trace macros that can be used for debugging and output. This group includes trace0, trace1, trace2, and trace3. These macros differ in the number of parameters they take. Trace0 only takes one formatted string and can be used for simple text messages. Trace1 takes a formatted string and adds a variable -- a variable that will be dumped. Similarly, trace2 and trace3 take two or three parameters respectively (after formatting the string ). If you use the release version of the application, it only dumps data to afxdump. Note: This macro is only valid in debug of MFC.

trace1 trace1 (exp, param1) Description: see trace0
trace2 trace2 (exp, param1, param2) Description: see trace0
trace3 trace3 (exp, param1, param2, param3) Description:
try Description: use this macro to create a try block. A try identifies a code block that can exclude exceptions. These exceptions are handled in subsequent catch and and_catch blocks. Transfer is allowed: An exception can be passed to an external try block, ignore them, or use the throw_last macro.
verify (booleanexpression) Description: In the debug version of MFC, verify macro calculates its variable value. If the result is 0, a macro prints a Diagnostic message and terminates the program. If the condition is not 0, nothing will be done. Diagnosis can be performed as follows: assertion failed in file in line where name is the name of the source file, and num is the stop row number that fails in the source file. In the release version of MFC, verify calculates the expression value but does not print or stop the program. For example, if the expression is a function call, the call is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.