Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
MFC
TRY
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

ON_COMMAND_RANGE 

Use this macro to map a contiguous range of command IDs to a single message handler function.


ON_COMMAND_RANGE(id1, id2, memberFxn )

Parameters

id1

Command ID at the beginning of a contiguous range of command IDs.

id2

Command ID at the end of a contiguous range of command IDs.

memberFxn

The name of the message-handler function to which the commands are mapped.

The range of IDs starts with id1 and ends with id2.

Use ON_COMMAND_RANGE to map a range of command IDs to one member function. Use ON_COMMAND to map a single command to a member function. Only one message-map entry can match a given command ID. That is, you can't map a command to more than one handler. For more information on mapping message ranges, see Handlers for Message-Map Ranges.

There is no automatic support for message map ranges, so you must place the macro yourself.

// The code fragment below shows how to use ON_COMMAND_RANGE macro
// to map a contiguous range of command IDs to a single message 
// handler function (i.e. OnFileMenuItems() is the sample below). In 
// addition, it also shows how to use CheckMenuRadioItem() to check a 
// selected menu item and makes it a radio item.
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
   // ... 
   ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()

void CMainFrame::OnFileMenuItems(UINT nID)
{
   CMenu* mmenu = GetMenu();
   CMenu* submenu = mmenu->GetSubMenu(0);
   submenu->CheckMenuRadioItem(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, 
      nID, MF_BYCOMMAND);
}

Community Additions

ADD
Show:
© 2015 Microsoft