private uint InsertMenuItemPrivate(IntPtr menuHandle, string textName, int position, RightClickActionDelegate actionDelegate) { if (mMenuItemsAddedCount >= mMenuMaximumItemsWeCanAdd) { return(0); } // Create a new Menu Item to add to the popup menu MENUITEMINFO mii = new MENUITEMINFO(); mii.cbSize = ( uint )Marshal.SizeOf(typeof(MENUITEMINFO)); mii.fMask = ( uint )MIIM.ID | ( uint )MIIM.TYPE | ( uint )MIIM.STATE; mii.wID = ( uint )(mMenuCmdFirst + mMenuItemsAddedCount); mii.fType = ( uint )MF.STRING; mii.dwTypeData = textName; mii.cch = 0; mii.fState = ( uint )MF.ENABLED; // Add it to the item if (DllImports.InsertMenuItem(menuHandle, (uint)position, true, ref mii) == 0) { // failed //int error = Marshal.GetLastWin32Error(); //System.Windows.Forms.MessageBox.Show( "InsertMenuItem failed + 0x" + error.ToString( "X" ) + " : " + ( new System.ComponentModel.Win32Exception( error ) ).Message ); return(0); } else { mMenuIdsMap.Add(mMenuItemsAddedCount, actionDelegate); mMenuItemsAddedCount++; return(mii.wID); } }
public uint InsertSubMenuIntoSubMenu(IntPtr menu, IntPtr subMenu, string textName, int position) { MENUITEMINFO mii = new MENUITEMINFO(); mii.cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO)); mii.fMask = (uint)MIIM.ID | (uint)MIIM.STRING | (uint)MIIM.SUBMENU; mii.wID = (uint)(mMenuCmdFirst + mMenuItemsAddedCount); mii.fType = (uint)MF.STRING; mii.dwTypeData = textName; mii.cch = 0; mii.fState = (uint)MF.ENABLED; mii.hSubMenu = subMenu; // Add it to the item if (DllImports.InsertMenuItem(menu, (uint)position, true, ref mii) == 0) { // failed return(0); } else { mMenuItemsAddedCount++; return(mii.wID); } }
public uint InsertSeperatorPrivate(IntPtr subMenu, int position) { MENUITEMINFO mii = new MENUITEMINFO(); mii.cbSize = ( uint )Marshal.SizeOf(typeof(MENUITEMINFO)); mii.fMask = ( uint )MIIM.ID; mii.wID = ( uint )(mMenuCmdFirst + mMenuItemsAddedCount); mii.fType = ( uint )MF.SEPARATOR; mii.cch = 0; mii.fState = ( uint )MF.ENABLED; // Add it to the item if (DllImports.InsertMenuItem(subMenu, (uint)position, true, ref mii) == 0) { // failed return(0); } else { mMenuItemsAddedCount++; return(mii.wID); } }