public static void ConstructCustomMenu(IntPtr menu, CustomMenuStructure[] customItems, uint idCmdFirst, out List <IntPtr> menuPtrConstructed, out List <IntPtr> imgPtrConstructed) { menuPtrConstructed = new List <IntPtr>(); imgPtrConstructed = new List <IntPtr>(); for (int i = 0; i < customItems.Length; i++) { CustomMenuStructure item = customItems[i]; if (item.IsFolder) { IntPtr newPopup = ShellAPI.CreatePopupMenu(); List <IntPtr> submenuPtrConstructed, subimgPtrConstructed; ConstructCustomMenu(newPopup, item.Items.ToArray(), idCmdFirst, out submenuPtrConstructed, out subimgPtrConstructed); insertMenu(menu, idCmdFirst, i, newPopup, item, ref imgPtrConstructed); menuPtrConstructed.Add(newPopup); menuPtrConstructed.AddRange(submenuPtrConstructed); imgPtrConstructed.AddRange(subimgPtrConstructed); } else if (item.Text == "---") { ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.SEPARATOR, 0, ""); } else { insertMenu(menu, idCmdFirst, i, IntPtr.Zero, item, ref imgPtrConstructed); } } }
internal static void ConstructCustomMenu(IntPtr menu, CustomMenuStructure[] customItems, out List <IntPtr> menuPtrConstructed) { menuPtrConstructed = new List <IntPtr>(); for (int i = 0; i < customItems.Length; i++) { CustomMenuStructure item = customItems[i]; if (item.IsFolder) { IntPtr newPopup = ShellAPI.CreatePopupMenu(); menuPtrConstructed.Add(newPopup); ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.POPUP, newPopup, item.Text); List <IntPtr> submenuPtrConstructed; ConstructCustomMenu(newPopup, item.Items.ToArray(), out submenuPtrConstructed); menuPtrConstructed.AddRange(submenuPtrConstructed); } else if (item.Text == "---") { ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.SEPARATOR, IntPtr.Zero, ""); } else { ShellAPI.MFT extraFlag = 0; if (item.Checked) { extraFlag |= ShellAPI.MFT.CHECKED; } ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | extraFlag, new UIntPtr(ShellAPI.CMD_LAST + item.ID + 1), item.Text); } } }
private static ShellAPI.MENUITEMINFO generateMenuItemInfo(CustomMenuStructure cms, uint idCmdFirst) { ShellAPI.MENUITEMINFO mii = new ShellAPI.MENUITEMINFO(); mii.cbSize = Marshal.SizeOf(mii); mii.wID = idCmdFirst + cms.ID; mii.fType = ShellAPI.MFT.MFT_STRING; mii.fMask = ShellAPI.MIIM.ID | ShellAPI.MIIM.TYPE; mii.dwTypeData = cms.Text; mii.fState = ShellAPI.MFS.ENABLED; if (cms.Checked) { mii.fState |= ShellAPI.MFS.CHECKED; } if (cms.IsFolder) { mii.fMask |= ShellAPI.MIIM.SUBMENU; } //Not working, dont know why... //if (cms.Icon != null) //{ // IntPtr ptrBitmap = cms.Icon.GetHbitmap(); // imgPtrConstructed.Add(ptrBitmap); // mii.hbmpItem = ptrBitmap; // mii.fMask |= ShellAPI.MIIM.BITMAP; // mii.fType |= ShellAPI.MFT.BITMAP; //} return(mii); }
public static void ConstructCustomMenu(IntPtr menu, CustomMenuStructure[] customItems, uint idCmdFirst, out List<IntPtr> menuPtrConstructed, out List<IntPtr> imgPtrConstructed) { menuPtrConstructed = new List<IntPtr>(); imgPtrConstructed = new List<IntPtr>(); for (int i = 0; i < customItems.Length; i++) { CustomMenuStructure item = customItems[i]; if (item.IsFolder) { IntPtr newPopup = ShellAPI.CreatePopupMenu(); List<IntPtr> submenuPtrConstructed, subimgPtrConstructed; ConstructCustomMenu(newPopup, item.Items.ToArray(), idCmdFirst, out submenuPtrConstructed, out subimgPtrConstructed); insertMenu(menu, idCmdFirst, i, newPopup, item, ref imgPtrConstructed); menuPtrConstructed.Add(newPopup); menuPtrConstructed.AddRange(submenuPtrConstructed); imgPtrConstructed.AddRange(subimgPtrConstructed); } else if (item.Text == "---") ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.SEPARATOR, 0, ""); else { insertMenu(menu, idCmdFirst, i, IntPtr.Zero, item, ref imgPtrConstructed); } } }
internal static CustomMenuStructure[] ParseCustomMenu(string[] menuTexts) { CustomMenuStructure root = new CustomMenuStructure(); for (uint i = 0; i < menuTexts.Length; i++) { string menuText = menuTexts[i]; string[] pathSplit = menuText.Split(new char[] { '\\' }); CustomMenuStructure current = root; foreach (string path in pathSplit) { if (current[path] == null) { current.Items.Add( new CustomMenuStructure(path, i)); //folder may inherit incorrect id, but they are ignored anyway. } current = current[path]; } } return(root.Items.ToArray()); }
private static void insertMenu(IntPtr menu, uint idCmdFirst, int pos, IntPtr newPopup, CustomMenuStructure item, ref List <IntPtr> imgPtrConstructed) { ShellAPI.MENUITEMINFO menuItemInfo = generateMenuItemInfo(item, idCmdFirst); if (newPopup != IntPtr.Zero) { menuItemInfo.hSubMenu = newPopup; } ShellAPI.InsertMenuItem(menu, (uint)pos, true, ref menuItemInfo); if (item.Icon != null) { IntPtr ptrBitmap = item.Icon.GetHbitmap(); imgPtrConstructed.Add(ptrBitmap); ShellAPI.SetMenuItemBitmaps(menu, (uint)pos, (uint)ShellAPI.MFT.BYPOSITION, ptrBitmap, ptrBitmap); } }
internal static void ConstructCustomMenu(IntPtr menu, CustomMenuStructure[] customItems, out List<IntPtr> menuPtrConstructed) { menuPtrConstructed = new List<IntPtr>(); for (int i = 0; i < customItems.Length; i++) { CustomMenuStructure item = customItems[i]; if (item.IsFolder) { IntPtr newPopup = ShellAPI.CreatePopupMenu(); menuPtrConstructed.Add(newPopup); ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.POPUP, newPopup, item.Text); List<IntPtr> submenuPtrConstructed; ConstructCustomMenu(newPopup, item.Items.ToArray(), out submenuPtrConstructed); menuPtrConstructed.AddRange(submenuPtrConstructed); } else if (item.Text == "---") ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | ShellAPI.MFT.SEPARATOR, IntPtr.Zero, ""); else { ShellAPI.MFT extraFlag = 0; if (item.Checked) extraFlag |= ShellAPI.MFT.CHECKED; ShellAPI.InsertMenu(menu, (uint)i, ShellAPI.MFT.BYPOSITION | extraFlag, new UIntPtr(ShellAPI.CMD_LAST + item.ID + 1), item.Text); } } }
internal static CustomMenuStructure[] ParseCustomMenu(string[] menuTexts) { CustomMenuStructure root = new CustomMenuStructure(); for (uint i = 0; i < menuTexts.Length; i++) { string menuText = menuTexts[i]; string[] pathSplit = menuText.Split(new char[] { '\\' }); CustomMenuStructure current = root; foreach (string path in pathSplit) { if (current[path] == null) current.Items.Add( new CustomMenuStructure(path, i)); //folder may inherit incorrect id, but they are ignored anyway. current = current[path]; } } return root.Items.ToArray(); }
private static void insertMenu(IntPtr menu, uint idCmdFirst, int pos, IntPtr newPopup, CustomMenuStructure item, ref List<IntPtr> imgPtrConstructed) { ShellAPI.MENUITEMINFO menuItemInfo = generateMenuItemInfo(item, idCmdFirst); if (newPopup != IntPtr.Zero) menuItemInfo.hSubMenu = newPopup; ShellAPI.InsertMenuItem(menu, (uint)pos, true, ref menuItemInfo); if (item.Icon != null) { IntPtr ptrBitmap = item.Icon.GetHbitmap(); imgPtrConstructed.Add(ptrBitmap); ShellAPI.SetMenuItemBitmaps(menu, (uint)pos, (uint)ShellAPI.MFT.BYPOSITION, ptrBitmap, ptrBitmap); } }
private static ShellAPI.MENUITEMINFO generateMenuItemInfo(CustomMenuStructure cms, uint idCmdFirst) { ShellAPI.MENUITEMINFO mii = new ShellAPI.MENUITEMINFO(); mii.cbSize = Marshal.SizeOf(mii); mii.wID = idCmdFirst + cms.ID; mii.fType = ShellAPI.MFT.MFT_STRING; mii.fMask = ShellAPI.MIIM.ID | ShellAPI.MIIM.TYPE; mii.dwTypeData = cms.Text; mii.fState = ShellAPI.MFS.ENABLED; if (cms.Checked) mii.fState |= ShellAPI.MFS.CHECKED; if (cms.IsFolder) mii.fMask |= ShellAPI.MIIM.SUBMENU; //Not working, dont know why... //if (cms.Icon != null) //{ // IntPtr ptrBitmap = cms.Icon.GetHbitmap(); // imgPtrConstructed.Add(ptrBitmap); // mii.hbmpItem = ptrBitmap; // mii.fMask |= ShellAPI.MIIM.BITMAP; // mii.fType |= ShellAPI.MFT.BITMAP; //} return mii; }