/// <summary> /// Handles the MouseUp event of the picTarget control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> private void picTarget_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { IntPtr hWnd; IntPtr hTemp; // End targeting isTargetingWindow = false; // Unhighlight window if (targetedWindowHandle != IntPtr.Zero) { Win32Ex.HighlightWindow(targetedWindowHandle); } targetedWindowHandle = IntPtr.Zero; // Reset capture image and cursor picTarget.Cursor = Cursors.Default; picTarget.Image = imageList.Images[0]; // Get screen coords from client coords and window handle hWnd = Win32Ex.WindowFromPoint(picTarget.Handle, e.X, e.Y); // Get owner while ((hTemp = Win32.GetParent(hWnd)) != IntPtr.Zero) { hWnd = hTemp; } ShowWindowInfo(hWnd, true); // Release capture Win32.SetCapture(IntPtr.Zero); }
/// <summary> /// Handles the MouseMove event of the picTarget control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> private void picTarget_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { IntPtr hWnd; IntPtr hTemp; Win32.POINTAPI pt; // TODO: Draw border around EVERY window pt.x = e.X; pt.y = e.Y; Win32.ClientToScreen(picTarget.Handle, ref pt); // Make sure targeting before highlighting windows if (!isTargetingWindow) { return; } // Get screen coords from client coords and window handle hWnd = Win32Ex.WindowFromPoint(picTarget.Handle, e.X, e.Y); // Get real window if (hWnd != IntPtr.Zero) { hTemp = IntPtr.Zero; while (true) { Win32.MapWindowPoints(hTemp, hWnd, ref pt, 1); hTemp = (IntPtr)Win32.ChildWindowFromPoint(hWnd, pt.x, pt.y); if (hTemp == IntPtr.Zero) { break; } if (hWnd == hTemp) { break; } hWnd = hTemp; } // TODO: Work with ALL windows /* * Win32.ScreenToClient(hWnd, ref pt); * Win32.MapWindowPoints(IntPtr.Zero, hWnd, ref pt, 2); * if ((hTemp = (IntPtr)Win32.ChildWindowFromPoint(hWnd, pt.x, pt.y)) != IntPtr.Zero) * { * hWnd = hTemp; * } */ } // Get owner while ((hTemp = Win32.GetParent(hWnd)) != IntPtr.Zero) { hWnd = hTemp; } // Show info ShowWindowInfo(hWnd, true); // Highlight valid window HighlightValidWindow(hWnd, Handle); }