// Copy a menu onto the beginning or end of another menu // Adds uIDAdjust to each menu ID (pass in 0 for no adjustment) // Will not add any item whose adjusted ID is greater than uMaxIDAdjust // (pass in 0xffff to Allow Everything // Returns One More Than THE MAXIMUM Adjusted ID That IS USED //
UINT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags) {int nItem; HMENU hmSubMenu; BOOL bAlreadySeparated; MENUITEMINFO miiSrc; TCHAR szName [256]; UINT uTemp, uIDMax = uIDAdjust;
IF (! hmdst ||! hmsrc) {goto mm_exit;}
NITEM = GetMenuItemCount (HMDST); if (uinsert> = (uint) nitem) {uinsert = (uint) NItem; BalReadySeparated = true;} else {balreadySeparated = _shismenuseparetor (hmdst, uinsert) ;;}
IF (UFlags & mm_AddseParator) {// add a separator Between the Menus InsertMenu (HMDST, UINSERT, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); BalReadySeparated = true;
// Go through the menu items and clone them for (nItem = GetMenuItemCount (hmSrc) - 1; nItem> = 0; nItem--) {miiSrc.cbSize = SIZEOF (MENUITEMINFO); miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA; // We need to reset this every time through the loop in case // menus DO NOT have IDs miiSrc.fType = MFT_STRING; miiSrc.dwTypeData = szName; miiSrc.dwItemData = 0; miiSrc.cch = Arraysize (szname);
IF (! GetMenuiteminfo (HMSRC, NITEM, TRUE, & MIISRC) {Continue;}
// if it's a separator, then add it. If the separator has smoking crash and news their butt kicked. IF ((Miisrc.FTYPE & MFT_SEPARATOR) && Eval (! Miisrc.hsubmenu)) {// this is a separator; don't put two of itm in a rowiff == -1 &&! (Uflags & mm_dreamseps)) {Continue;} BalReadySeparated = true;} else} else .hsubmenu) {if (uflags & mm_submenushaveids) {// adjust the id and check it miisrc.wid = uidadjust; if (miisrc.wid> uidadjustmax) {Continue;}
IF (UidMax <= miisrc.wid) {uidmax = miisrc.wid 1;}} else {// Don't set ids for submenus That Didn't Have /////////>
HMSUBMENU = Miisrc.hsubmenu; miisrc.hsubmenu = createpopupmenu (); if (! miisrc.hsubmenu) {goto mm_exit;}
Utemp = shell_mergemenus (Miisrc.hsubmenu, HMSubmenu, 0, UidAdjust, UidJustmax, UFLAGS & MM_SUBMENUSHAVEIDS); if (uidmax <= utemp) {uidmax = utemp;}
bAlreadySeparated = FALSE;} else {// Adjust the ID and check it miiSrc.wID = uIDAdjust; if (miiSrc.wID> uIDAdjustMax) {continue;} if (uIDMax <= miiSrc.wID) {uIDMax = miiSrc.wID 1; }
Balreadyseparated = false;}
IF (! EVAL (HMDST, UINSERT, TRUE, & MIISRC)) {goto mm_exit;}}
// Ensure the correct number of separators at the beginning of the // inserted menu items if (uInsert == 0) {if (bAlreadySeparated && (uFlags & MM_DONTREMOVESEPS)!) {DeleteMenu (hmDst, uInsert, MF_BYPOSITION);}} else {if (_SHIsMenuSeparator (hmDst, uInsert-1)) {if (bAlreadySeparated && (uFlags & MM_DONTREMOVESEPS)!) {DeleteMenu (hmDst, uInsert, MF_BYPOSITION);}} else {if (! (uFlags & MM_ADDSEPARATOR) && bAlreadySeparated) { // Add a separator Between The Menus InsertMenu (HMDST, UINSERT, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);}}}
MM_EXIT: #ifdef debug dbcheckmenu (hmdst); # endif return (uidmax);