Share via


COMMAND_HANDLER

COMMAND_HANDLER( id**,** code**,** func )

Parameters

id

[in] The identifier of the menu item, control, or accelerator.

code

[in] The notification code.

func

[in] The name of the message-handler function.

Remarks

Defines an entry in a message map. COMMAND_HANDLER maps a message to the specified handler function, based on the notification code and the control identifier. For example:

class CMyClass : ...
{
public:
   ...

   BEGIN_MSG_MAP(CMyClass)
      COMMAND_HANDLER(IDC_MYCTL, EN_CHANGE, OnChange)
      ...
   END_MSG_MAP()

   // When a CMyClass object receives a WM_COMMAND
   // message identified by IDC_MYCTL and EN_CHANGE,
   // the message is directed to CMyClass::OnChange
   // for the actual processing.
   LRESULT OnChange( ... )
   { ... }

};

Any function specified in a COMMAND_HANDLER macro must defined as follows:

LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

The message map sets bHandled to TRUE before CommandHandler is called. If CommandHandler does not fully handle the message, it should set bHandled to FALSE to indicate the message needs further processing.

Note   Always begin a message map with BEGIN_MSG_MAP. You can then declare subsequent alternate message maps with ALT_MSG_MAP. The END_MSG_MAP macro marks the end of the message map. Every message map must have exactly one instance of BEGIN_MSG_MAP and END_MSG_MAP.

In addition to COMMAND_HANDLER, you can use MESSAGE_HANDLER to map a WM_COMMAND message without regard to an identifier or code. In this case, MESSAGE_HANDLER(WM_COMMAND, OnHandlerFunction) will direct all WM_COMMAND messages to OnHandlerFunction.

For more information about using message maps in ATL, see Message Maps in the article "ATL Window Classes."

ATL Macros and Global Functions

See Also

COMMAND_ID_HANDLER, COMMAND_CODE_HANDLER, COMMAND_RANGE_HANDLER, NOTIFY_HANDLER