Ejemplo n.º 1
0
        public void UpdateMenu(SystemMenuItem menuItem)
        {
            var mii = new MENUITEMINFO
            {
                fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING
            };

            mii.cbSize = (uint)Marshal.SizeOf(mii);

            PInvokeUtils.Try(() => GetMenuItemInfo(_hSysMenu, menuItem.Id, false, ref mii));

            if (menuItem.Enabled)
            {
                mii.fState &= (~MFS_DISABLED); // clear "disabled" flag
            }
            else
            {
                mii.fState |= MFS_DISABLED;    // set "disabled" flag
            }
            if (menuItem.Checked)
            {
                mii.fState |= MFS_CHECKED;    // set "checked" flag
            }
            else
            {
                mii.fState &= (~MFS_CHECKED); // clear "checked" flag
            }
            mii.fMask = MIIM_STATE;

            PInvokeUtils.Try(() => SetMenuItemInfo(_hSysMenu, menuItem.Id, false, ref mii));

            // TODO: From my observations, this function always returns false, even though it appears to succeed.
            //       Am I using it incorrectly?
            DrawMenuBar(_hSysMenu);
        }
Ejemplo n.º 2
0
        public SystemMenuItem CreateMenuItem(string text = null, EventHandler clickHandler = null)
        {
            var menuItem = new SystemMenuItem(_menuItemIdCounter++)
            {
                Text = text
            };

            if (clickHandler != null)
            {
                menuItem.Clicked += clickHandler;
            }

            return(menuItem);
        }
Ejemplo n.º 3
0
 public void InsertMenu(uint position, SystemMenuItem menuItem)
 {
     PInvokeUtils.Try(() => InsertMenu(_hSysMenu, position, MF_BYPOSITION | MF_STRING, menuItem.Id, menuItem.Text));
     _items.Add(menuItem);
 }
Ejemplo n.º 4
0
 public void AppendMenu(SystemMenuItem menuItem)
 {
     PInvokeUtils.Try(() => AppendMenu(_hSysMenu, MF_STRING, menuItem.Id, menuItem.Text));
     _items.Add(menuItem);
 }