On_command_range macro in VC ++ (example)

Source: Internet
Author: User
Tags ranges

From: http://www.cnblogs.com/wqj1212/articles/1089066.html

The on_command_range macro and on_command macro in VC ++ are used to declare the message processing function.
On_command is different. This macro can be used to define a group of message processing functions.

The two macros are used as follows:
On_command (ID, memberfxn)
On_command_range (id1, Id2, memberfxn)

It seems that there is no difference in memberfxn, but in learning to use it, it is found that memberfxn in the on_command_range macro is often defined as a processing function with parameters, on_command is a processing function without parameters. This made me strange, so I checked the msdn explanation, following the clues provided, I found chapter handlers for message-map ranges in Visual C ++ programmer's guide, so I found the answer in the "declaring the handler function" section and referenced the original article as follows:

Handler functions for single commands normally take no parameters. with the exception of update handler functions, Handler functions for message-map ranges require an extra parameter, NID, of Type uint. this parameter is the first parameter. the extra parameter accommodates the extra command ID needed to specify which command the user actually chose.

In order to help my friends who do not know English as well as me, I am under my head:
The processing function of a single command (Message) usually does not contain parameters. However, an additional parameter, a uint type NID, is required for the update handler and the handler for the message ing range. This parameter is the first parameter. This additional parameter collects the command ID used to specify the command that the user selects.

Therefore, you can use a message processing function with parameters to receive the specified command ID. However, please note that there is not only one parameter, you can use message processing functions with multiple parameters, such as function (wparam, lparam). However, the first parameter wparam is the user-selected command ID.

The on_update_command_ui_range macro corresponding to on_command_range also exists for the update handler. It also serves to process the continuous range (Contiguous range), but it is slightly different from on_command_range. As shown above, generally, the range processing function (on_command_range) adds a parameter after the processing function. When the message is processed, the command ID is passed to the parameter. On_update_command_ui_range uses pcmdui, A ccmdui pointer type, which contains a data member (m_nid) to point to the command ID. For details, see the content in msdn. The above content can be found in the handlers for message-map ranges chapter example for a range of command IDs in Visual C ++ programmer's guide in msdn. original article:

Update handler functions for single commands normally take a single parameter, pcmdui, of Type ccmdui *. unlike handler functions, update handler functions for message-map ranges do not require an extra parameter, NID, of Type uint. the command ID, which is needed to specify which command the user actually chose, is found in the ccmdui object.

Which means:
The update handler function of a single command usually only includes one parameter, that is, a ccmdui pointer type pcmdui. Unlike normal processing functions, the update processing function for the message ing range does not require an additional uint parameter NID, which is used to specify the command ID that you actually select, can be found in the ccmdui object.

 

Example

When I was working on a calculator, I added nine IDC_OPERATION1--IDC_OPERATION9 button controls to the dialog box, using on_command_range (bn_clicked, idc_operation9, onoperation) for message ing,

In ** DLG. H
// Generated message map Functions
// {Afx_msg (cmydlg)
Afx_msg void onoperation (uint NID );
..........

//} Afx_msg
Declare_message_map ()
In the ** DLG. cpp File
On_command_range (bn_clicked, idc_operation9, onoperation)

In resource. H
# Define idc_operation1 1001
# Define idc_operation2 1002
# Define idc_operation3 1003
# Deprecision idc_operation4 1004
# Define idc_operation5 1005
# Define idc_operation6 1006
# Define idc_operation7 1007
# Define idc_operation8 8 1008
# Define idc_operation9 1009

C ** DLG: onoperation (uint NID)
{
.......
Switch (NID)
{
Case idc_operation1:
.......;
Break;
Case idc_operation2:
.......
Break;
........
........
}

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.