public void Highlight() { IntPtr windowDC; RECT windowRect = new RECT(0, 0, 0, 0); NativeUtils.GetWindowRect(detectedWindow, ref windowRect); IntPtr parentWindow = NativeUtils.GetParent(detectedWindow); windowDC = NativeUtils.GetWindowDC(detectedWindow); if (windowDC != IntPtr.Zero) { Graphics graph = Graphics.FromHdc(windowDC, detectedWindow); graph.DrawRectangle(drawPen, 1, 1, windowRect.Width - 2, windowRect.Height - 2); graph.Dispose(); NativeUtils.ReleaseDC(detectedWindow, windowDC); } }