コード例 #1
0
ファイル: WindowsMenu.cs プロジェクト: JianwenSun/cc
        // Return menuItem object which is a hierarchical parent of the given menu (specified via hwnd)
        // return NULL in the case when menu does not have a parent (e.g. Context menu)
        // NOTE: this method should not be called for the menuItem that lives on the System or Menubar
        internal static MenuItem GetHierarchyParent(IntPtr hwnd)
        {
            int ownerMenuItemPos = -1;
            IntPtr menuParent = IntPtr.Zero;
            IntPtr hwndParent = IntPtr.Zero;

            IntPtr menu = HmenuFromHwnd(hwnd);
            if (menu == IntPtr.Zero)
            {
                throw new ElementNotAvailableException();
            }
            MenuType currentType = GetSubMenuType(hwnd, menu);
            MenuType parentType = MenuType.Toplevel;

            if (currentType == MenuType.Submenu)
            {
                if (!GetSubMenuParent(hwnd, out menuParent, out hwndParent, out ownerMenuItemPos, out parentType))
                {
                    return null;
                }

                ProxyFragment parent = null;
                if (parentType == MenuType.Toplevel)
                {
                    // Top Level Menu.
                    // We need to have the parenthood defined in the same way as if it was done 
                    // from the non client area code.

                    NonClientArea nonClientArea = new NonClientArea(hwndParent);
                    parent = nonClientArea.CreateNonClientChild(NonClientArea.NonClientItem.Menu);
                }
                else
                {
                    parent = new WindowsMenu(hwndParent, null, menuParent, parentType, ownerMenuItemPos);
                }

                return new MenuItem(hwndParent, parent, ownerMenuItemPos, menuParent, parentType);
            }

            return null;
        }
コード例 #2
0
ファイル: WindowsMenu.cs プロジェクト: JianwenSun/cc
            private MenuItem FirstOrLastChild (bool returnFirstChild)
            {
                // Return first or last menuItem on the menu that this menuItem will drop
                if (_type == MenuItemType.SubMenu && IsEnabledMenu)
                {
                    IntPtr hSubmenu = UnsafeNativeMethods.GetSubMenu(_hmenu, _item);
                    if (hSubmenu == IntPtr.Zero)
                    {
                        return null;
                    }
                    IntPtr hwndSubmenu = WindowsMenu.WindowFromSubmenu(hSubmenu);

                    if (hwndSubmenu != IntPtr.Zero)
                    {
                        WindowsMenu.MenuType type = WindowsMenu.GetSubMenuType(hwndSubmenu, hSubmenu);
                        WindowsMenu parent = new WindowsMenu(hwndSubmenu, null, hSubmenu, type, 0);
                        int childIndex = (returnFirstChild) ? 0 : Misc.GetMenuItemCount(hSubmenu) - 1;

                        return new MenuItem(hwndSubmenu, parent, childIndex, hSubmenu, type);
                    }
                    return null;
                }

                return null;
            }
コード例 #3
0
ファイル: WindowsMenu.cs プロジェクト: JianwenSun/cc
        private static IRawElementProviderSimple Create(IntPtr hwnd, int idChild)
        {
            MenuType type = MenuType.Toplevel;
            IntPtr hmenu;

            try
            {
                hmenu = UnsafeNativeMethods.GetMenu(hwnd);

                if (hmenu == IntPtr.Zero)
                {
                    hmenu = HmenuFromHwnd(hwnd);
                    if (hmenu == IntPtr.Zero)
                    {
                        // bail
                        return null;
                    }
                }
                // get type of the submenu
                type = GetSubMenuType(hwnd, hmenu);
            }
            catch (ElementNotAvailableException)
            {
                return null;
            }

            WindowsMenu windowsMenu = new WindowsMenu(hwnd, null, hmenu, type, 0);
            if (idChild == 0)
            {
                return windowsMenu;
            }
            else
            {
                return windowsMenu.CreateMenuItem(idChild - 1);
            }
        }
コード例 #4
0
ファイル: WindowsMenu.cs プロジェクト: JianwenSun/cc
            // ------------------------------------------------------
            //
            // Constructors
            //
            // ------------------------------------------------------

            #region Constructors

            internal MenuItem (IntPtr hwnd, ProxyFragment parent, int item, IntPtr hmenu, WindowsMenu.MenuType type)
            : base(hwnd, parent, item)
            {
                _fNonClientAreaElement = true;
                _menuType = type;
                _hmenu = hmenu;
                _type = GetMenuItemType ();

                if (_type == MenuItemType.Spacer)
                {
                    _cControlType = ControlType.Separator;
                    _sAutomationId = "Separator " + (_item + 1).ToString(CultureInfo.InvariantCulture); // This string is a non-localizable string
                    _fIsContent = false;
                }
                else
                {
                    _cControlType = ControlType.MenuItem;
                    GetItemId(ref _sAutomationId);
                }
            }
コード例 #5
0
        internal ProxyHwnd CreateNonClientMenu ()
        {
            // child windows don't have menus
            int style = WindowStyle;
            if (!Misc.IsBitSet(style, NativeMethods.WS_CHILD))
            {
                ProxyHwnd menuProxy = null;

                if (WindowsMenu.IsInSystemMenuMode())
                {
                    // Since in system menu mode try to find point on the SystemMenu
                    WindowsTitleBar titleBar = (WindowsTitleBar)CreateNonClientChild(NonClientItem.TitleBar);
                    if (titleBar != null)
                    {
                        menuProxy = (ProxyHwnd)titleBar.CreateTitleBarChild(WindowsTitleBar._systemMenu);
                    }
                }
                else
                {
                    IntPtr menu = UnsafeNativeMethods.GetMenu(_hwnd);
                    if (menu != IntPtr.Zero)
                    {
                        menuProxy = new WindowsMenu(_hwnd, this, menu, WindowsMenu.MenuType.Toplevel, (int)NonClientItem.Menu);
                    }
                }

                if (menuProxy != null)
                {
                    // if this menu is not visible its really not there
                    if (menuProxy.BoundingRectangle.Width != 0 && menuProxy.BoundingRectangle.Height != 0)
                    {
                        return menuProxy;
                    }
                }
            }

            return null;
        }
コード例 #6
0
        private static IRawElementProviderSimple CreateMenuBarItem(IntPtr hwnd, int idChild)
        {
            IntPtr menu = UnsafeNativeMethods.GetMenu(hwnd);

            if (menu == IntPtr.Zero)
            {
                return null;
            }

            NonClientArea nonClientArea = new NonClientArea( hwnd );

            WindowsMenu appMenu = new WindowsMenu(hwnd, nonClientArea, menu, WindowsMenu.MenuType.Toplevel, (int) NonClientItem.Menu);

            if (idChild == 0)
            {
                return appMenu;
            }
            else
            {
                return appMenu.CreateMenuItem(idChild - 1);
            }
        }