Exemple #1
0
        public static void MouseUp(IntPtr ParentHandle, IntPtr Handle, int x, int y, MouseButton Button, MouseKeyModifier Keys)
        {
            bool hooked = false;

            WaitToBeVisibleAndEnabled(Handle);
            Block(ParentHandle, Handle);
            try
            {
                NM.tagPoint thePoint = new NM.tagPoint();
                thePoint.x = x;
                thePoint.y = y;
                IntPtr TopLevelHandle = NM.ChildWindowFromPoint(NM.GetDesktopWindow(), thePoint);

                NM.tagRect WindowSize;
                NM.GetWindowRect(Handle, out WindowSize);

                thePoint.x = x + WindowSize.left;
                thePoint.y = y + WindowSize.top;
                IntPtr ChildHandle = NM.WindowFromPoint(thePoint);

                if (!WaitForInputIdle(ChildHandle, GUI.m_APE.TimeOut))
                {
                    throw new Exception("Window did not go idle within timeout");
                }

                IntPtr ActualParent;

                if (ParentHandle == IntPtr.Zero)
                {
                    ActualParent = Handle;
                }
                else
                {
                    ActualParent = ParentHandle;
                }

                TimerResolution.SetMaxTimerResolution();

                //TODO this looks wrong should use clickcommon only for this
                if (ChildHandle == ActualParent)
                {
                    ClickCommon(ParentHandle, Handle, x, y);
                }
                else
                {
                    MouseMove(Handle, x, y, false);
                }

                if (Handle == ActualParent)
                {
                    GUI.m_APE.AddFirstMessageAddMouseHook(Handle);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                    hooked = true;
                }

                MouseClick(Button, false, true, 1, Keys.HasFlag(MouseKeyModifier.Control), Keys.HasFlag(MouseKeyModifier.Shift));

                if (Handle == ActualParent)
                {
                    GUI.m_APE.AddFirstMessageWaitForMouseState((APEIPC.MouseButton)Button, false, true);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                }
            }
            catch
            {
                Reset();    //Reset the mouse blocking
                throw;
            }
            finally
            {
                try
                {
                    if (hooked)
                    {
                        GUI.m_APE.AddFirstMessageRemoveMouseHook(Handle);
                        GUI.m_APE.SendMessages(EventSet.APE);
                        GUI.m_APE.WaitForMessages(EventSet.APE);
                    }
                }
                finally
                {
                    TimerResolution.UnsetMaxTimerResolution();
                    Unblock();
                    IsMouseDown = false;
                }
            }
        }
Exemple #2
0
        private void IdentifyButton_Click(object sender, EventArgs e)
        {
            m_CurrentAttached = (KeyValuePair <Process, string>)WinformsProcessesCombobox.SelectedItem;

            if (m_CurrentAttached.Key.HasExited)
            {
                WinformsProcessesCombobox.SelectedIndex = 0;
                Populate();
                return;
            }

            IdentifyButton.Enabled            = false;
            WinformsProcessesCombobox.Enabled = false;
            label1.Text = "Move the mouse cursor over the desired window and then press the control key";

            //install hotkey hook for control key
            if (!NM.RegisterHotKey(this.Handle, 1, NM.MOD_CONTROL, NM.VK_CONTROL))
            {
                throw new Exception("Failed to register hotkey");
            }
            m_ControlKey = false;

            IntPtr OldHandle = IntPtr.Zero;

            while (m_ControlKey == false)
            {
                Point       cursorPosition = Cursor.Position;
                NM.tagPoint screenLocation;
                NM.tagPoint Location;
                IntPtr      Handle;
                IntPtr      ChildWindow;
                IntPtr      parent = NM.GetDesktopWindow();
                screenLocation.x = cursorPosition.X;
                screenLocation.y = cursorPosition.Y;

                while (true)
                {
                    Location = screenLocation;
                    NM.ScreenToClient(parent, ref Location);
                    ChildWindow = NM.RealChildWindowFromPoint(parent, Location);

                    if (ChildWindow == IntPtr.Zero || parent == ChildWindow)
                    {
                        Handle = parent;
                        break;
                    }

                    parent = ChildWindow;
                }

                uint Pid;
                NM.GetWindowThreadProcessId(Handle, out Pid);

                if (Handle != OldHandle)
                {
                    if (OldHandle != IntPtr.Zero)
                    {
                        ClearHighlight(m_Area);
                    }

                    if (m_CurrentAttached.Key.Id == Pid)
                    {
                        PopulatePropertyListbox(NM.GetAncestor(Handle, NM.GetAncestorFlags.GetRoot), Handle);

                        Highlight(Handle);

                        OldHandle = Handle;
                    }
                    else
                    {
                        OldHandle = IntPtr.Zero;
                    }
                }

                Application.DoEvents();
                Thread.Sleep(100);
            }

            if (OldHandle != IntPtr.Zero)
            {
                ClearHighlight(m_Area);

                TreeNode[] Nodes = WindowTree.Nodes.Find(m_Identity.ParentHandle.ToString() + ":" + m_Identity.Handle.ToString(), true);
                if (Nodes.GetLength(0) == 0)
                {
                    BuildTree();
                    Nodes = WindowTree.Nodes.Find(m_Identity.ParentHandle.ToString() + ":" + m_Identity.Handle.ToString(), true);
                }
                if (Nodes.GetLength(0) > 0)
                {
                    WindowTree.SelectedNode = Nodes[0];
                    WindowTree.Focus();
                }
            }

            if (!m_Closing)
            {
                NM.UnregisterHotKey(this.Handle, 1);
                label1.Text                       = "";
                IdentifyButton.Enabled            = true;
                WinformsProcessesCombobox.Enabled = true;
            }
        }