Dynamic addition and dynamic response to menu items when writing a game map editor, which records some of the issues and solutions that come up. Because the game map is a hierarchical storage and display, there is a Layer menu in the editor main menu. In addition to a "show" menu item and a sperator, other menu items are based on the map The number of layers and the name of the layer is dynamically added, so the number of menu items cannot be known in the compile period, or the ON_COMMAND macro will be associated with the command processing function. There is also an on_command_range macro that can associate an ID within a range with a Command Handler, but if this is, I have to specify the largest ID number in this macro. Because I don't know how many layers in the actual map, I don't want the dynamically added menu item to have a maximum on the ID. The first menu item of the Layer menu is "show online", which responded to the update_command_ui message, I first delete all the menu items after "Show Only" in this response function, and check how many layers actually have actually, get the map Name, add menu items according to the actual number of layers. The code that deletes the menu item is as follows: nitemcount = PlayerMenu-> getMenuItemcount (); for (i = 2; i