Beispiel #1
0
        public void UpdateMenu(IWindowMenuItem menuItem)
        {
            var mii = new MENUITEMINFO(null)
            {
                fMask = MenuItemInfoMember.MIIM_CHECKMARKS |
                        MenuItemInfoMember.MIIM_DATA |
                        MenuItemInfoMember.MIIM_FTYPE |
                        MenuItemInfoMember.MIIM_ID |
                        MenuItemInfoMember.MIIM_STATE |
                        MenuItemInfoMember.MIIM_STRING
            };

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

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

            PInvokeUtils.Try(() => SystemMenuAPI.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?
            SystemMenuAPI.DrawMenuBar(_hSysMenu);
        }