예제 #1
0
        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);
            }
        }
예제 #2
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);
            }
        }