Exemplo n.º 1
0
        /// <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;

            NativeWin32.POINTAPI pt;

            // TODO: Draw border around EVERY window

            pt.x = e.X;
            pt.y = e.Y;
            NativeWin32.ClientToScreen(picTarget.Handle, ref pt);

            // Make sure targeting before highlighting windows
            if (!isTargeting)
            {
                return;
            }

            // Get screen coords from client coords and window handle
            hWnd = NativeWin32.WindowFromPoint(picTarget.Handle, e.X, e.Y);

            // Get real window
            if (hWnd != IntPtr.Zero)
            {
                hTemp = IntPtr.Zero;

                while (true)
                {
                    NativeWin32.MapWindowPoints(hTemp, hWnd, ref pt, 1);
                    hTemp = (IntPtr)NativeWin32.ChildWindowFromPoint(hWnd, pt.x, pt.y);
                    if (hTemp == IntPtr.Zero)
                    {
                        break;
                    }
                    if (hWnd == hTemp)
                    {
                        break;
                    }
                    hWnd = hTemp;
                }

                /* TODO: Work with ALL windows
                 * NativeWin32.ScreenToClient(hWnd, ref pt);
                 * NativeWin32.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 = NativeWin32.GetParent(hWnd)) != IntPtr.Zero)
            {
                hWnd = hTemp;
            }

            // Show info
            SetWindowHandle(hWnd);

            // Highlight valid window
            HighlightValidWindow(hWnd, this.Handle);
        }