Esempio n. 1
0
        /// <summary>
        /// Highlights the specified window, but only if it is a valid window in relation to the specified owner window.
        /// </summary>
        private void HighlightValidWindow(IntPtr hWnd, IntPtr hOwner)
        {
            // Check for valid highlight
            if (targetWindow == hWnd)
            {
                return;
            }

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

                return;
            }

            // Unhighlight last window
            NativeWin32.HighlightWindow(targetWindow);

            // Set as current target
            targetWindow = hWnd;

            // Highlight window
            NativeWin32.HighlightWindow(hWnd);
        }
Esempio n. 2
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
            isTargeting = false;

            // Unhighlight window
            if (targetWindow != IntPtr.Zero)
            {
                NativeWin32.HighlightWindow(targetWindow);
            }
            targetWindow = IntPtr.Zero;

            // Reset capture image and cursor
            picTarget.Cursor = Cursors.Default;
            picTarget.Image  = bitmapFind;

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

            // Get owner
            while ((hTemp = NativeWin32.GetParent(hWnd)) != IntPtr.Zero)
            {
                hWnd = hTemp;
            }

            SetWindowHandle(hWnd);

            // Release capture
            NativeWin32.SetCapture(IntPtr.Zero);
        }