New items are added to the pop-up menu inherited from an object's ancestors by overriding the object's wpModifyPopupMenu and calling wpInsertPopupMenuItems. For example, to add New item to MyObject's pop-up menu, the new menu item is defined in a resource file in the same manner as menus are defined in PM programs. An ID is assigned to the new menu and to the menu item, as shown in the following sample code:
#define ID_MOREITEMS WPMENUID_USER+1 #define ID_NEWITEMS WPMENUID_USER+2 MENU ID_MOREITEMS LOADONCALL MOVEABLE DISCARDABLE BEGIN MENUITEM "New Item", ID_NEWITEMS END
Menu items can also be deleted by overriding wpModifyPopupMenu and by sending the MM_DELETEITEM message to the menu.
User defined menu items must be greater than 0x6500. IDs for class-specific menus and menu items have a value greater than WPMENUID_USER, so they do not conflict with IDs for menus and menu items defined by the Workplace Shell classes, as shown in the following sample code:
/* Add a new item to MyObject's pop-up menu */ SOM_Scope BOOL32 SOMLINK MyObject_wpModifyPopupMenu (MyObject *somSelf,HWND hwndMenu, HWND hwndCnr, ULONG ulPosition) /* Remove an item from MyObject's pop-up menu */ WinSendMsg(hwndMenu, MM_DELETEITEM, MPFROM2SHORT(MY_ITEMID,FALSE), NULL); { /* Insert new items in MyObject's primary menu */ _wpInsertPopupMenuItemsA(somSelf, hwndMenu, ulPosition, hmod, ID_MOREITEMS, WPMENUID_PRIMARY); /* Add the items inherited from MyObject's parent */ return (parent_wpModifyPopupMenu(somSelf, hwndMenu, hwndCnr, ulPosition)); }
The wpInsertPopupMenuItems method requires:
In the above sample code, ID_MOREITEMS is the ID for the menu resource that defines the new menu item being added to the object's primary pop-up menu. WPMENUID_PRIMARY is the ID for the object's primary pop-up menu, where New item is being inserted.
An item can be added to a pop-up submenu or conditional cascaded menu by specifying the ID for the conditional cascaded menu on the call to wpInsertPopupMenuItems. For example, to add New item to the Open conditional cascaded menu, the call to wpInsertPopupMenuItems is modified as shown in the following sample code:
/* Insert new items in MyObject's Open submenu */_wpInsertPopupMenuItemsA(somSelf, hwndMenu, ulPosition, hmod, ID_MOREITEMS, WPMENUID_OPEN);