Пример #1
0
        private void SetReplaceItems(ContextMenu menu)
        {
            foreach (var item in replaceItems)
            {
                var count = WinApiFunctions.GetMenuItemCount(menu.Handle);
                var index = item.Index < 0 ? count + item.Index : item.Index;

                var itemInfo = new MENUITEMINFO();
                itemInfo.cbSize = Marshal.SizeOf(itemInfo);
                itemInfo.fMask  = MIIM.MIIM_ID | MIIM.MIIM_SUBMENU;

                if (WinApiFunctions.GetMenuItemInfo(menu.Handle, index, true, ref itemInfo))
                {
                    actions[itemInfo.wID] = item.Action;
                }
            }
        }
Пример #2
0
 private void SetNewItems(ContextMenu menu)
 {
     foreach (var item in newItems)
     {
         var newItemInfo = new MENUITEMINFO();
         newItemInfo.cbSize = Marshal.SizeOf(newItemInfo);
         newItemInfo.fMask  = MIIM.MIIM_CHECKMARKS | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE |
                              MIIM.MIIM_STRING;
         newItemInfo.fType        = (uint)Consts.MFT_STRING;
         newItemInfo.fState       = (uint)Consts.MFS_ENABLED;
         newItemInfo.wID          = actions.Count + 1;
         actions[newItemInfo.wID] = item.Action;
         //  newItemInfo.hbmpChecked = hBitmap;
         //  newItemInfo.hbmpUnchecked = hBitmap;
         newItemInfo.dwTypeData = item.Text;
         newItemInfo.cch        = 8;
         WinApiFunctions.InsertMenuItem(menu.Handle, item.Index, true, ref newItemInfo);
     }
 }
Пример #3
0
 public static extern bool InsertMenuItem(IntPtr hMenu, int uItem, bool fByPosition, ref MENUITEMINFO lpmii);