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(); }
private void Highlight(IntPtr hWnd) { m_Area = Display.GetWindowRectangleDIP(hWnd); 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)); NM.Rectangle(hWindowDC, m_Area.left, m_Area.top, m_Area.right, m_Area.bottom); NM.SelectObject(hWindowDC, hPrevPen); NM.SelectObject(hWindowDC, hPrevBrush); NM.ReleaseDC(Handle, hWindowDC); }