예제 #1
0
파일: APE.Spy.cs 프로젝트: johnsewell/APE
        private void LocateButton_Click(object sender, EventArgs e)
        {
            if (WindowTree.SelectedNode != null)
            {
                string[] SplitCharacters = { ":" };
                string[] Handles         = WindowTree.SelectedNode.Name.Split(SplitCharacters, StringSplitOptions.None);

                IntPtr ParentHandle = new IntPtr(int.Parse(Handles[0]));
                IntPtr Handle       = new IntPtr(int.Parse(Handles[1]));

                if (NM.IsWindow(Handle) && NM.IsWindowVisible(Handle))
                {
                    if (ParentHandle == IntPtr.Zero)
                    {
                        NM.BringWindowToTop(Handle);
                    }
                    else
                    {
                        NM.BringWindowToTop(ParentHandle);
                    }

                    NM.tagRect area = Display.GetWindowRectangleDIP(Handle);

                    IntPtr hWindowDC     = NM.GetDC(IntPtr.Zero);
                    IntPtr hRectanglePen = NM.CreatePen(NM.PenStyle.PS_SOLID, 3, (uint)ColorTranslator.ToWin32(Color.Red));
                    IntPtr hPrevPen      = NM.SelectObject(hWindowDC, hRectanglePen);
                    IntPtr hPrevBrush    = NM.SelectObject(hWindowDC, NM.GetStockObject(NM.StockObjects.HOLLOW_BRUSH));

                    for (int i = 0; i < 3; i++)
                    {
                        NM.Rectangle(hWindowDC, area.left, area.top, area.right, area.bottom);
                        Thread.Sleep(300);
                        ClearHighlight(area);
                        if (i < 2)
                        {
                            Thread.Sleep(300);
                        }
                    }

                    NM.SelectObject(hWindowDC, hPrevPen);
                    NM.SelectObject(hWindowDC, hPrevBrush);
                    NM.ReleaseDC(Handle, hWindowDC);
                }
                else
                {
                    BuildTree();
                }
            }

            WindowTree.Focus();
        }
예제 #2
0
파일: APE.Spy.cs 프로젝트: johnsewell/APE
 private void ObjectSpy_Activate(object sender, System.EventArgs e)
 {
     WindowTree.Focus();
 }
예제 #3
0
파일: APE.Spy.cs 프로젝트: johnsewell/APE
        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;
            }
        }