Meanings of commonly used Macros in Visual C ++ MFC

Source: Internet
Author: User
Tags terminates
And_catchand_catch

And_catch (exception_class, exception _ object_point_name)

Note:


DefineCodeBlock, 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 subsequent exception handling.
The code can access the exception object (if appropriate) and has received 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
Department 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 the user is
Scope defines variables, so remember that they can only be accessed in this scope. It is also usedPrediction_object_pointer_name variable.

Assert

Assert (booleanexpression)

Note:


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 form of diagnostic messages is:
Assertion failed in file in line where name is the Meta File Name and num is the interrupt number for failed operations in the source file.
In the release version, assert does not compute the expression value and does not interruptProgram. 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

Assert_vaild (pobject)

Note:


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
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

Begin_message_map (the class, baseclass)

Note:

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)

Note:


Use this to define a code block, which 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 get more information about the special causes of the exception.
Multiple messages. Call the throw_last macro to set the processing process as an external exception framework. If exception-class is a class c0000tioon, all
Exception type. You can use the cobject: iskindof member function to confirm that the special exception is excluded. The best way to obtain exceptions is to use the sequential and_catch language.
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

Note:


Helps to 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 ),
The name and row number of each object record allocated to debug_new. Then, when you use the cmemorystate: dumpallobjectsince member function
The file name and row number are displayed for each place where the objects allocated with debug_new are distributed. To use debug_new, insert the following command in the user's resource file:
# Define new debug_new
Once you insert this command, the Preprocessing Program inserts debug_new in the place where new is used, while MFC performs the rest of the work. However, when you compile a release version of your program,
Debug_new performs a simple new operation without generating the file name and row number messages.

Declare_dynamic

Declare_dynamic (class_name)

Note:


However, 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 access
This module is included in the. cpp file of the word class object. 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 at runtime. If declare_dynamic is included in the class definition,
Implemetn_dynamic must be included in the class tool.

Declare_dyncreate

Declare_dyncreate (class_name)

Note:


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, such
When reading an object from a disk, 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. However
And then include this pattern 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

Declare_message_map ()

Note:


Each csf-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, in the definition
In the. cpp file of the class member function, the begin_message_map macro is used. The list under the macro item of each user's message processing function and the end_message_map macro are used.

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

Declare_serial (class_name)

Note:


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
In the class definition, implement_serial must be included in the class tool. The declare_serial macro contains all declare_dynamic,
Implement_dycreate.


End_catch

End_catch

Note:

The end of the final catch or and_catch block.

End_message_map

End_message_map

Note:

Use the end_message_map macro to end your message ing definition.

Implement_dynamic

Implement_dynamic (class_name, base_class_name)

Note:

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

Implement_dyncreate (class_name, base_class_name)

Note:


Use the declare_dyncreate macro to use the implement_dyncreate macro to allow the cobject derived class object to be automatically created at runtime. Host enabling
This function is used 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
Declare_dyncreate and implement_dyncreate macros, then use the runtime_class macro and cobject ::
Iskindof member function to determine the object class at runtime. If declare_dyncreate is included in the definition, implement_dyncreate must be included
Included in tools.

Implement_serial

Implement_serial (class_name, base_class_name, wschema)

Note:

The necessary C ++ code is established through the class name and position of the dynamic cobject derived class in the serial structure during runtime. Use the implement_serial macro in the. cpp file, and then link the result object code once.

On_command

On_command (ID, memberfxn)

Note:


This macro inserts a message ing by classwizard or manually. It indicates that the function will process a command consumption from a command User Interface (such as a menu item or toolbar button)
. When a command object receives a Windows
When a wm_command message is sent, on_command calls the member function memberfxn to process the message. In user message ing, for each menu or accelerator command (must be
Ing to a message processing function) There must be an on_command macro statement.

On_control

On_control (wnotifycode, ID, memberfxn)

Note:

Indicates which function will process a general control to indicate the message. Control identifies messages that are sent from a controller to the parent window.

On_message

On_message (message, memberfxn)

Note:


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 those that are not standard windows
Any message of the wm_message message. 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

On_registered_message (nmessagevarible, memberfxn)

Note:

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

On_update_command_ui (ID, memberfxn)

Note:

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

On_vbxevent (wnotifycode, memberfxn)

Note:

This macro usually inserts a message ing through classwizard to indicate which function will process a message from vbx control. In message ing, each vbx Control Message mapped to a message processing function should have a macro statement.

Runtime_class

Runtime_class (class_name)

Note:


Use this macro to obtain the class structure during runtime from the C ++ class. Runtime_class returns a pointer to cruntimeclass for the class specified by class_name.
Structure. Only cobject Derived classes defined by declare_dynamic, declare_dyncreate, or declare_serial are returned to one
The pointer to the cruntimeclass structure.

Throw

Throw (exception_object_pointer)

Note:

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

Throw_last ()

Note:

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)

Note:


Send a formatted string to a dump device, such as a file or debugging monitor, and provide functions similar to printf. Same as printf of C program in ms_dos, trace macro
Is a convenient form of tracking variable values when the program is 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)

Note:


Similar to the trace, but it places the trace string in the code segment, instead of the dgroup, So it uses less dgroup space. Trace0 is a variant of a group of Trace macros that can
Used for debugging output. This group includes trace0, trace1, trace2, and trace3. These macros differ in the number of parameters they take. Trace0 only takes one formatted character
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 (
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)

Note:

See trace0

Trace2

Trace2 (exp, param1, param2)

Note:

See trace0

Trace3

Trace3 (exp, param1, param2, param3)

Note:

Try

Try

Note:

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

Verify (booleanexpression)

Note:


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
Here, name is the name of the source file, and num is the stop line number that failed 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.