Ejemplo n.º 1
0
        public void Destroy()
        {
            var menuHandle = GetSystemMenu(WindowHandle, false);

            foreach (var item in _menuItems.Items.Where(x => x.Show))
            {
                var id = MenuItemId.GetId(item.Name);
                if (id > 0)
                {
                    DeleteMenu(menuHandle, id, Constants.MF_BYCOMMAND);
                }
            }

            DeleteMenu(menuHandle, MenuItemId.SC_SEPARATOR_BOTTOM, Constants.MF_BYCOMMAND);

            var numberItems = GetMenuItemCount(menuHandle);

            if (numberItems == DEFAULT_SYSTEM_MENU_NUMBER_ITEMS)
            {
                GetSystemMenu(WindowHandle, true);
            }
        }
Ejemplo n.º 2
0
        public bool Create()
        {
            var menuHandle = GetSystemMenu(WindowHandle, false);

            if (menuHandle == IntPtr.Zero)
            {
                return(false);
            }

            foreach (var item in _menuItems.Items)
            {
                if (item.Type == MenuItemType.Item && item.Show)
                {
                    var id    = MenuItemId.GetId(item.Name);
                    var title = GetTransparencyTitle(id);
                    title = GetTitle(item.Name, title, true);
                    if (!IsMenuItem(menuHandle, id))
                    {
                        InsertMenu(menuHandle, MenuItemId.SC_CLOSE, Constants.MF_BYCOMMAND, id, title);
                    }
                }

                if (item.Type == MenuItemType.Separator && item.Show)
                {
                    InsertMenu(menuHandle, MenuItemId.SC_CLOSE, Constants.MF_BYCOMMAND | Constants.MF_SEPARATOR, MenuItemId.SC_SEPARATOR, null);
                }

                if (item.Type == MenuItemType.Group && item.Show)
                {
                    var subMenuHandle = CreateMenu();

                    if (item.Name.ToLower() == "size")
                    {
                        for (int i = 0; i < _menuItems.WindowSizeItems.Count; i++)
                        {
                            var subItemId = MenuItemId.SC_SIZE_DEFINED + i;
                            _menuItems.WindowSizeItems[i].Id = subItemId;
                            if (!IsMenuItem(subMenuHandle, subItemId))
                            {
                                AppendMenu(subMenuHandle, Constants.MF_BYCOMMAND, subItemId, GetTitle(_menuItems.WindowSizeItems[i]));
                            }
                        }
                    }

                    if (item.Name.ToLower() == "move_to")
                    {
                        foreach (var moveToMenuItem in MoveToMenuItems)
                        {
                            AppendMenu(subMenuHandle, Constants.MF_BYCOMMAND, MenuItemId.SC_MOVE_TO + moveToMenuItem.Key, GetTitle("monitor") + moveToMenuItem.Key);
                        }
                    }

                    if (item.Name.ToLower() == "start_program")
                    {
                        for (int i = 0; i < _menuItems.StartProgramItems.Count; i++)
                        {
                            AppendMenu(subMenuHandle, Constants.MF_BYCOMMAND, MenuItemId.SC_START_PROGRAM + i, _menuItems.StartProgramItems[i].Title);
                        }
                    }

                    foreach (var subItem in item.Items)
                    {
                        if (subItem.Type == MenuItemType.Item && subItem.Show)
                        {
                            var subItemId = MenuItemId.GetId(subItem.Name);
                            var title     = GetTransparencyTitle(subItemId);
                            title = GetTitle(subItem.Name, title, true);
                            if (!IsMenuItem(subMenuHandle, subItemId))
                            {
                                InsertMenu(subMenuHandle, -1, Constants.MF_BYCOMMAND, subItemId, title);
                            }
                        }

                        if (subItem.Type == MenuItemType.Separator && subItem.Show)
                        {
                            InsertMenu(subMenuHandle, -1, Constants.MF_BYCOMMAND | Constants.MF_SEPARATOR, MenuItemId.SC_SEPARATOR, null);
                        }
                    }

                    var id = MenuItemId.GetId(item.Name);
                    if (!IsMenuItem(menuHandle, id))
                    {
                        InsertSubMenu(menuHandle, subMenuHandle, MenuItemId.SC_CLOSE, Constants.MF_BYCOMMAND | Constants.MF_POPUP, (uint)id, GetTitle(item.Name, null, true));
                    }
                    subMenuHandle = IntPtr.Zero;
                }
            }

            if (!IsMenuItem(menuHandle, MenuItemId.SC_SEPARATOR_BOTTOM))
            {
                InsertMenu(menuHandle, MenuItemId.SC_CLOSE, Constants.MF_BYCOMMAND | Constants.MF_SEPARATOR, MenuItemId.SC_SEPARATOR_BOTTOM, null);
            }

            return(true);
        }