From: http://www.blogjava.net/tanzek/archive/2008/01/26/177905.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 thatMemberfxnThere seems to be no difference, but in learning to use it, we found thatMemberfxnIt is often defined as a processing function with parameters, while on_command is a processing function without parameters. This made me strange, so I checked the msdn explanation and found 《Visual c ++ programmer's GuideIn "handlers for message-map ranges", the answer is found in the section "declaring the handler function". The original reference is 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 TypeUint. 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 typeNid. 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, message Processing functions with multiple parameters, suchFunction (wparam, lparam)But the real usable parameter is the first parameter.WparamIt is the user-selected command ID.
For the update handler function, there are also corresponding to on_command_rangeOn_update_command_ui_rangeMacro, which is also used 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 usesPcmdui, OneCcmduiIt contains a data member (m_nid), which is used to point to the command ID. For details, see the content in msdn. In 《Visual c ++ programmer's GuideIn handlers for message-map ranges, you can find the original article in chapter example for a range of command IDs:
Update handler functions for single commands normally take a single parameter,Pcmdui, Of TypeCcmdui *. Unlike handler functions, update handler functions for message-map ranges do not require an extra parameter,Nid, Of TypeUint. The command ID, which is needed to specify which command the user actually chose, is found inCcmduiObject.
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.