Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Highlights the specified window, if valid.
        /// </summary>
        private void HighlightValidWindow(IntPtr hWnd, IntPtr hOwner)
        {
            // Check for valid highlight
            if (targetedWindowHandle == hWnd)
            {
                return;
            }

            // Check for relative
            if (Win32Ex.IsRelativeWindow(hWnd, hOwner, true))
            {
                // Unhighlight last window
                if (targetedWindowHandle != IntPtr.Zero)
                {
                    Win32Ex.HighlightWindow(targetedWindowHandle);
                    targetedWindowHandle = IntPtr.Zero;
                }

                return;
            }

            // Unhighlight last window
            Win32Ex.HighlightWindow(targetedWindowHandle);

            // Set as current target
            targetedWindowHandle = hWnd;

            // Highlight window
            Win32Ex.HighlightWindow(hWnd);
        }