Ejemplo n.º 1
0
        void button_Click(object sender, EventArgs e)
        {
            McButton button = (McButton)sender;

            if (button.aeMenu != null)
            {
                List <MenuUtilities.MenuItem> mil = MenuUtilities.GetMenuItems(button.aeMenu, true);
                if (mil.Count > 0)
                {
                    AddButtons(mil);
                }
                else
                {
                    HighlightLastClicked(button);
                    MenuUtilities.ClickMenuItem(button.aeMenu);
                }
            }
            else
            {
                string[] tag = ((McButton)sender).Tag.ToString().Split(';');
                IntPtr   ips = WindowsAPI.GetSubMenu((IntPtr)Convert.ToInt32(tag[0]), Convert.ToInt32(tag[1]));
                if (WindowsAPI.GetMenuItemCount(ips) > 0)
                {
                    AddButtons(MenuUtilities.GetMenuItems(ips));
                }
                else
                {
                    HighlightLastClicked(button);
                    IntPtr hMenu = new IntPtr(Convert.ToInt32(tag[0]));
                    MenuUtilities.ClickMenuItem(hMenu, Convert.ToInt32(tag[1]), _currentWnd);
                }
            }
        }
Ejemplo n.º 2
0
        public static List <MenuUtilities.MenuItem> GetMenuItems(int hWnd)
        {
            List <MenuUtilities.MenuItem> mil = null;

            AutomationElement aeMainForm = AutomationElement.FromHandle(new IntPtr(hWnd));

            AutomationElementCollection aeMenuBars = GetMenuBar(aeMainForm);

            if (aeMenuBars != null && aeMenuBars.Count > 0)
            {
                mil = MenuUtilities.GetMenuItems(aeMenuBars[0]);
            }

            return(mil);
        }
Ejemplo n.º 3
0
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            if (DisplayBehavior == DisplayBehaviorTypes.AutoHideMenuController)
            {
                Point pos     = this.PointToClient(Cursor.Position);
                bool  entered = this.ClientRectangle.Contains(pos);
                if (entered != _mouseEntered)
                {
                    _mouseEntered = entered;
                    if (!entered)
                    {
                        Collapse(false);
                        WindowsAPI.SetForegroundWindow(new IntPtr(_currentWnd));
                    }
                    else if (pbContainer.Controls.Count > 0)
                    {
                        Expand();
                        WindowsAPI.SetForegroundWindow(this.Handle);
                    }
                }
            }

            Int32 hWnd = WindowsAPI.GetForegroundWindow();

            if (hWnd == (Int32)this.Handle)
            {
                _lastWndWasThis = true;
            }
            else if (_lastWndWasThis)
            {
                _lastWndWasThis = false;
                _currentWnd     = 0;
            }
            if (hWnd != _currentWnd && hWnd != (Int32)this.Handle && hWnd != 0)
            {
                _currentWnd = hWnd;
                IntPtr ip = WindowsAPI.GetMenu(_currentWnd);
                List <MenuUtilities.MenuItem> mil = null;
                if ((int)ip != 0)
                {
                    mil = MenuUtilities.GetMenuItems(ip);
                    if (mil.Count == 0)
                    {
                        mil = MenuUtilities.GetMenuItems(_currentWnd);
                    }
                }
                else
                {
                    mil = MenuUtilities.GetMenuItems(_currentWnd);
                }

                if (mil != null && mil.Count > 0)
                {
                    AddButtons(mil);
                    lblVersion.Text      = VERSION + " - IN-FOCUS WINDOW COMPATIBLE.";
                    lblVersion.BackColor = Color.PaleGreen;
                    if (DisplayBehavior != DisplayBehaviorTypes.AutoHideMenuController)
                    {
                        Expand();
                    }
                }
                else
                {
                    lblVersion.Text      = VERSION + " - IN-FOCUS WINDOW NOT COMPATIBLE.";
                    lblVersion.BackColor = Color.LightPink;
                    Collapse(true);
                }
            }
        }