Esempio n. 1
0
        /// <summary>
        /// This method will capture the current Cursor by using User32 Code
        /// </summary>
        /// <returns>A IElement with the Mouse Cursor as Image in it.</returns>
        public static bool TryGetCurrentCursor(out BitmapSource bitmapSource, out NativePoint location)
        {
            bitmapSource = null;
            location     = NativePoint.Empty;
            var cursorInfo = CursorInfo.Create();

            if (!NativeCursorMethods.GetCursorInfo(ref cursorInfo))
            {
                return(false);
            }

            if (cursorInfo.Flags != CursorInfoFlags.Showing)
            {
                return(false);
            }

            using (var safeIcon = NativeIconMethods.CopyIcon(cursorInfo.CursorHandle))
            {
                if (!NativeIconMethods.GetIconInfo(safeIcon, out var iconInfo))
                {
                    return(false);
                }

                using (iconInfo.BitmaskBitmapHandle)
                    using (iconInfo.ColorBitmapHandle)
                    {
                        var cursorLocation = User32Api.GetCursorLocation();
                        bitmapSource = Imaging.CreateBitmapSourceFromHIcon(safeIcon.DangerousGetHandle(), Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        location     = new NativePoint(cursorLocation.X - iconInfo.Hotspot.X, cursorLocation.Y - iconInfo.Hotspot.Y);
                    }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Called from Surface (the parent) if a mouse move is made while drawing
        /// </summary>
        /// <returns>true if the surface doesn't need to handle the event</returns>
        public override bool HandleMouseMove(int mouseX, int mouseY)
        {
            NativePoint previousPoint = capturePoints[capturePoints.Count - 1];

            if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= 2 * EditorConfig.FreehandSensitivity)
            {
                capturePoints.Add(new NativePoint(mouseX, mouseY));
            }
            if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) < EditorConfig.FreehandSensitivity)
            {
                return(true);
            }
            //path.AddCurve(new NativePoint[]{lastMouse, new NativePoint(mouseX, mouseY)});
            lastMouse = new NativePoint(mouseX, mouseY);
            lock (_freehandPathLock)
            {
                freehandPath.AddLine(lastMouse, new NativePoint(mouseX, mouseY));
                // Only re-calculate the bounds & redraw when we added something to the path
                NativeRectFloat rect = freehandPath.GetBounds();
                myBounds = rect.Round();
            }

            Invalidate();
            return(true);
        }
Esempio n. 3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // ...
            var wParam = HitTestOnMouseDown();

            // ...
            if (wParam != HitTestValues.NOWHERE)
            {
                // ...
                NativeMethods.ReleaseCapture();

                // ...
                var location = new NativePoint {
                    X = (short)MousePosition.X, Y = (short)MousePosition.Y
                };
                var button = SystemInformation.MouseButtonsSwapped
                                        ? (int)WindowMessages.WM_NCRBUTTONDOWN
                                        : (int)WindowMessages.WM_NCLBUTTONDOWN;

                // ...
                var lParam = (ushort)location.X | (location.Y << 16);
                NativeMethods.SendMessage(Parent.Handle, button, (int)wParam, lParam);
            }

            // ...
            base.OnMouseDown(e);
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the specified peek (live preview) bitmap for the specified
        /// window.  This is typically done in response to a DWM message.
        /// </summary>
        /// <param name="hwnd">The window handle.</param>
        /// <param name="bitmap">The thumbnail bitmap.</param>
        /// <param name="offset">The client area offset at which to display
        /// the specified bitmap.  The rest of the parent window will be
        /// displayed as "remembered" by the DWM.</param>
        /// <param name="displayFrame">Whether to display a standard window
        /// frame around the bitmap.</param>
        internal static void SetPeekBitmap(IntPtr hwnd, IntPtr bitmap, System.Drawing.Point offset, bool displayFrame)
        {
            var nativePoint = new NativePoint(offset.X, offset.Y);
            int rc          = DwmSetIconicLivePreviewBitmap(
                hwnd,
                bitmap,
                ref nativePoint,
                displayFrame ? DisplayFrame : (uint)0);

            if (rc != 0)
            {
                Exception e = Marshal.GetExceptionForHR(rc);

                if (e is ArgumentException)
                {
                    // Ignore argument exception as it's not really recommended to be throwing
                    // exception when rendering the peek bitmap. If it's some other kind of exception,
                    // then throw it.
                }
                else
                {
                    throw e;
                }
            }
        }
Esempio n. 5
0
        public override bool Contains(int x, int y)
        {
            if (base.Contains(x, y))
            {
                return(true);
            }
            var clickedPoint = new NativePoint(x, y);

            if (Status != EditStatus.UNDRAWN)
            {
                var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
                var lineColor     = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
                using (var pen = new Pen(lineColor, lineThickness))
                {
                    using (var bubblePath = CreateBubble(lineThickness))
                    {
                        bubblePath.Widen(pen);
                        if (bubblePath.IsVisible(clickedPoint))
                        {
                            return(true);
                        }
                    }
                    using (var tailPath = CreateTail())
                    {
                        tailPath.Widen(pen);
                        if (tailPath.IsVisible(clickedPoint))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
 private void SetValuesOnSerializing(StreamingContext context)
 {
     if (TargetAdorner != null)
     {
         _storedTargetGripperLocation = TargetAdorner.Location;
     }
 }
        protected virtual bool Current()
        {
            System.IntPtr hwnd;
            if (!GetActiveWindow(out hwnd))
            {
                return(false);
            }
            NativeRect rect;

            if (!GetClientRect(hwnd, out rect))
            {
                Debug.LogError("Failed to Get Client Rect");
                return(false);
            }
            var point = new NativePoint()
            {
                x = rect.left, y = rect.top
            };

            if (!ClientToScreen(hwnd, ref point))
            {
                Debug.LogError("Failed to convert client to screen");
                return(false);
            }

            data.x      = point.x;
            data.y      = point.y;
            data.width  = rect.right - rect.left;
            data.height = rect.bottom - rect.top;
            return(true);
        }
        /// <summary>
        ///     Go to the previous "page"
        /// </summary>
        /// <returns>bool if this worked</returns>
        public bool Previous()
        {
            var result        = false;
            var hasScrollInfo = TryRetrievePosition(out var scrollInfoBefore);

            switch (ScrollMode)
            {
            case ScrollModes.KeyboardPageUpDown:
                result = KeyboardInputGenerator.KeyPresses(VirtualKeyCode.Prior) == 2;
                break;

            case ScrollModes.WindowsMessage:
                result = SendScrollMessage(ScrollBarCommands.SB_PAGEUP);
                break;

            case ScrollModes.AbsoluteWindowMessage:
                if (!hasScrollInfo)
                {
                    return(false);
                }
                // Calculate previous position, clone the scrollInfoBefore
                var scrollInfoForPrevious = scrollInfoBefore;
                scrollInfoForPrevious.Position = Math.Max(scrollInfoBefore.Minimum, scrollInfoBefore.Position - (int)scrollInfoBefore.PageSize);
                result = ApplyPosition(ref scrollInfoForPrevious);
                break;

            case ScrollModes.MouseWheel:
                var bounds      = ScrollingWindow.GetInfo().Bounds;
                var middlePoint = new NativePoint(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
                result = MouseInputGenerator.MoveMouseWheel(WheelDelta, middlePoint) == 1;
                break;
            }
            return(result);
        }
Esempio n. 9
0
        /// <summary>
        ///     The mouse move handler of the capture form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            var cursorLocation         = User32Api.GetCursorLocation();
            var relativeCursorPosition = WindowCapture.GetLocationRelativeToScreenBounds(cursorLocation);

            // Make sure the mouse coordinates are fixed, e.g. when pressing shift
            _mouseMovePos = FixMouseCoordinates(relativeCursorPosition);
        }
Esempio n. 10
0
 internal Point(IntPtr nativePtr)
 {
     using (var native = new NativePoint(nativePtr))
     {
         this._X = native.X;
         this._Y = native.Y;
     }
 }
Esempio n. 11
0
 /// <summary>
 ///     Called from Surface (the _parent) when the drawing begins (mouse-down)
 /// </summary>
 /// <returns>true if the surface doesn't need to handle the event</returns>
 public override bool HandleMouseDown(int mouseX, int mouseY)
 {
     if (TargetAdorner == null)
     {
         _initialGripperPoint = new NativePoint(mouseX, mouseY);
         InitAdorner(Color.Green, new NativePoint(mouseX, mouseY));
     }
     return(base.HandleMouseDown(mouseX, mouseY));
 }
Esempio n. 12
0
        /// <summary>
        ///     Unscale the supplied NativePoint according to the supplied dpi
        /// </summary>
        /// <param name="size">NativePoint to unscale</param>
        /// <param name="dpi">current dpi, normal is 96.</param>
        /// <param name="scaleModifier">A function which can modify the scale factor</param>
        /// <returns>NativePoint unscaled</returns>
        public static NativePoint UnscaleWithDpi(NativePoint size, uint dpi, Func <double, double> scaleModifier = null)
        {
            var dpiUnscaleFactor = DpiUnscaleFactor(dpi);

            if (scaleModifier != null)
            {
                dpiUnscaleFactor = scaleModifier(dpiUnscaleFactor);
            }
            return(new NativePoint((int)(dpiUnscaleFactor * size.X), (int)(dpiUnscaleFactor * size.Y)));
        }
 /// <summary>Creates a new instance of the Message struct</summary>
 /// <param name="windowHandle">Window handle</param>
 /// <param name="msg">Message</param>
 /// <param name="wparam">WParam</param>
 /// <param name="lparam">LParam</param>
 /// <param name="time">Time</param>
 /// <param name="point">Point</param>
 internal Message(IntPtr windowHandle, uint msg, IntPtr wparam, IntPtr lparam, int time, NativePoint point)
     : this()
 {
     this.windowHandle = windowHandle;
     this.msg          = msg;
     this.wparam       = wparam;
     this.lparam       = lparam;
     this.time         = time;
     this.point        = point;
 }
Esempio n. 14
0
        /// <summary>
        ///     The coordinates need to be mapped from 0-65535 where 0 is left and 65535 is right
        /// </summary>
        /// <param name="location">NativePoint</param>
        /// <returns>NativePoint</returns>
        private static NativePoint RemapLocation(NativePoint location)
        {
            var bounds = DisplayInfo.ScreenBounds;

            if (bounds.Width * bounds.Height == 0)
            {
                return(location);
            }
            return(new NativePoint(location.X * (65535 / bounds.Width), location.Y * (65535 / bounds.Height)));
        }
 /// <summary>
 /// Creates a new instance of the Message struct
 /// </summary>
 /// <param name="windowHandle">Window handle</param>
 /// <param name="msg">Message</param>
 /// <param name="wparam">WParam</param>
 /// <param name="lparam">LParam</param>
 /// <param name="time">Time</param>
 /// <param name="point">Point</param>
 internal Message(IntPtr windowHandle, uint msg, IntPtr wparam, IntPtr lparam, int time, NativePoint point)
     : this()
 {
     this.windowHandle = windowHandle;
     this.msg = msg;
     this.wparam = wparam;
     this.lparam = lparam;
     this.time = time;
     this.point = point;
 }
Esempio n. 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap">
        ///
        /// </param>
        /// <param name="opacity">
        /// Specifies an alpha transparency value to be used on the entire source
        /// bitmap. The SourceConstantAlpha value is combined with any per-pixel
        /// alpha values in the source bitmap. The value ranges from 0 to 255. If
        /// you set SourceConstantAlpha to 0, it is assumed that your image is
        /// transparent. When you only want to use per-pixel alpha values, set
        /// the SourceConstantAlpha value to 255 (opaque).
        /// </param>
        public void SelectBitmap(Bitmap bitmap, int opacity)
        {
            // Does this bitmap contain an alpha channel?
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32bpp with alpha-channel.");
            }

            // Get device contexts
            IntPtr screenDc   = GetDC(IntPtr.Zero);
            IntPtr memDc      = CreateCompatibleDC(screenDc);
            IntPtr hBitmap    = IntPtr.Zero;
            IntPtr hOldBitmap = IntPtr.Zero;

            try {
                // Get handle to the new bitmap and select it into the current
                // device context.
                hBitmap    = bitmap.GetHbitmap(Color.FromArgb(0));
                hOldBitmap = SelectObject(memDc, hBitmap);

                // Set parameters for layered window update.
                NativeSize    newSize        = new NativeSize(bitmap.Width, bitmap.Height);
                NativePoint   sourceLocation = new NativePoint(0, 0);
                NativePoint   newLocation    = new NativePoint(this.Left, this.Top);
                BLENDFUNCTION blend          = new BLENDFUNCTION();
                blend.BlendOp             = AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = (byte)opacity;
                blend.AlphaFormat         = AC_SRC_ALPHA;

                // Update the window.
                UpdateLayeredWindow(
                    this.Handle,                         // Handle to the layered window
                    screenDc,                            // Handle to the screen DC
                    ref newLocation,                     // New screen position of the layered window
                    ref newSize,                         // New size of the layered window
                    memDc,                               // Handle to the layered window surface DC
                    ref sourceLocation,                  // Location of the layer in the DC
                    0,                                   // Color key of the layered window
                    ref blend,                           // Transparency of the layered window
                    ULW_ALPHA                            // Use blend as the blend function
                    );
            }
            finally {
                // Release device context.
                ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    SelectObject(memDc, hOldBitmap);
                    DeleteObject(hBitmap);
                }
                DeleteDC(memDc);
            }
        }
Esempio n. 17
0
		internal static System.Drawing.Size GetNonClientArea(IntPtr hwnd) {
			var c = new NativePoint();

			TabbedThumbnailNativeMethods.ClientToScreen(hwnd, ref c);

			var r = new NativeRect();

			TabbedThumbnailNativeMethods.GetWindowRect(hwnd, ref r);

			return new System.Drawing.Size(c.X - r.Left, c.Y - r.Top);
		}
Esempio n. 18
0
        public LocationPool()
        {
            var screenBounds  = DisplayInfo.AllDisplayInfos[0].Bounds;
            var pipNativeSize = new NativeSize(screenBounds.Width / 5, screenBounds.Height / 5);

            for (int i = 0; i < 5; i++)
            {
                var pipLocation = new NativePoint(screenBounds.Width - pipNativeSize.Width, i * pipNativeSize.Height);
                var currentSize = new NativeRect(pipLocation, pipNativeSize);
                _availableLocations.Add(currentSize);
            }
        }
Esempio n. 19
0
        internal Point(IntPtr ptr, bool isEnabledDispose = true)
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));
            }

            using (var native = new NativePoint(ptr, isEnabledDispose))
            {
                this._X = native.X;
                this._Y = native.Y;
            }
        }
Esempio n. 20
0
        /// <summary>
        ///     Create a MouseInput struct for a mouse move
        /// </summary>
        /// <param name="location">Where is the click located</param>
        /// <param name="timestamp">The time stamp for the event</param>
        /// <returns>MouseInput</returns>
        public static MouseInput MouseMove(NativePoint location, uint timestamp = 0)
        {
            location = RemapLocation(location);
            var bounds = DisplayInfo.GetAllScreenBounds();

            return(new MouseInput
            {
                dx = location.X * (65535 / bounds.Width),
                dy = location.Y * (65535 / bounds.Height),
                Timestamp = timestamp,
                MouseEventFlags = MouseMoveMouseEventFlags
            });
        }
Esempio n. 21
0
        /// <summary>
        ///     This creates the capture form
        /// </summary>
        /// <param name="capture">ICapture</param>
        /// <param name="windows">IList of IInteropWindow</param>
        public CaptureForm(ICapture capture, IList <IInteropWindow> windows)
        {
            if (_currentForm != null)
            {
                Log.Warn().WriteLine("Found currentForm, Closing already opened CaptureForm");
                _currentForm.Close();
                _currentForm = null;
                Application.DoEvents();
            }
            _currentForm = this;

            // Enable the AnimatingForm
            EnableAnimation = true;

            // clean up
            FormClosed += ClosedHandler;

            _capture        = capture;
            _windows        = windows;
            UsedCaptureMode = capture.CaptureDetails.CaptureMode;

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            Text = "Greenshot capture form";

            // Unregister at close
            FormClosing += ClosingHandler;

            // set cursor location
            _cursorPos = WindowCapture.GetCursorLocationRelativeToScreenBounds();

            // Initialize the animations, the window capture zooms out from the cursor to the window under the cursor
            if (UsedCaptureMode == CaptureMode.Window)
            {
                _windowAnimator = new RectangleAnimator(new NativeRect(_cursorPos, NativeSize.Empty), _captureRect, FramesForMillis(700), EasingTypes.Quintic, EasingModes.EaseOut);
            }

            // Set the zoomer animation
            InitializeZoomer(Conf.ZoomerEnabled);

            SuspendLayout();
            Bounds = capture.ScreenBounds;
            ResumeLayout();

            // Fix missing focus
            ToFront = true;
            TopMost = true;
        }
Esempio n. 22
0
        /// <summary>
        ///     Create a MouseInput struct for a mouse move
        /// </summary>
        /// <param name="location">Where is the click located</param>
        /// <param name="timestamp">The time stamp for the event</param>
        /// <returns>MouseInput</returns>
        public static MouseInput MouseMove(NativePoint location, uint?timestamp = null)
        {
            location = RemapLocation(location);
            var bounds      = DisplayInfo.ScreenBounds;
            var messageTime = timestamp ?? (uint)Environment.TickCount;

            return(new MouseInput
            {
                dx = location.X * (65535 / bounds.Width),
                dy = location.Y * (65535 / bounds.Height),
                Timestamp = messageTime,
                MouseEventFlags = MouseMoveMouseEventFlags
            });
        }
Esempio n. 23
0
        /// <summary>
        ///     Checks if the Zoom area can move there where it wants to go, change direction if not.
        /// </summary>
        /// <param name="pos">preferred destination location for the zoom area</param>
        /// <param name="allowZoomOverCaptureRect">
        ///     false to try to find a location which is neither out of screen bounds nor
        ///     intersects with the selected rectangle
        /// </param>
        private void VerifyZoomAnimation(NativePoint pos, bool allowZoomOverCaptureRect)
        {
            var screenBounds = DisplayInfo.GetBounds(MousePosition);

            // convert to be relative to top left corner of all screen bounds
            screenBounds = screenBounds.MoveTo(WindowCapture.GetLocationRelativeToScreenBounds(screenBounds.Location));
            var relativeZoomSize = Math.Min(screenBounds.Width, screenBounds.Height) / 5;

            // Make sure the final size is a plural of 4, this makes it look better
            relativeZoomSize = relativeZoomSize - relativeZoomSize % 4;
            var zoomSize   = new NativeSize(relativeZoomSize, relativeZoomSize);
            var zoomOffset = new NativePoint(20, 20);

            var targetRectangle = _zoomAnimator.Final.Offset(pos);

            if (screenBounds.Contains(targetRectangle) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(targetRectangle)))
            {
                return;
            }
            var destinationLocation = NativePoint.Empty;
            var tl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height);
            var tr = new NativeRect(pos.X + zoomOffset.X, pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height);
            var bl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height);
            var br = new NativeRect(pos.X + zoomOffset.X, pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height);

            if (screenBounds.Contains(br) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(br)))
            {
                destinationLocation = new NativePoint(zoomOffset.X, zoomOffset.Y);
            }
            else if (screenBounds.Contains(bl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(bl)))
            {
                destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, zoomOffset.Y);
            }
            else if (screenBounds.Contains(tr) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tr)))
            {
                destinationLocation = new NativePoint(zoomOffset.X, -zoomOffset.Y - zoomSize.Width);
            }
            else if (screenBounds.Contains(tl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tl)))
            {
                destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, -zoomOffset.Y - zoomSize.Width);
            }
            if (destinationLocation == NativePoint.Empty && !allowZoomOverCaptureRect)
            {
                VerifyZoomAnimation(pos, true);
            }
            else
            {
                _zoomAnimator.ChangeDestination(new NativeRect(destinationLocation, zoomSize));
            }
        }
Esempio n. 24
0
            static public cScreen FromPoint(NativePoint p)
            {
                foreach (var cs in cScreen.screens)
                {
                    if (cs != null && cs.Bounds.Width > 250)
                    {
                        if (p.X >= cs.Bounds.Left && p.X <= cs.Bounds.Right)
                        {
                            return(cs);
                        }
                    }
                }

                return(null);
            }
Esempio n. 25
0
		internal static System.Drawing.Point GetParentOffsetOfChild(IntPtr hwnd, IntPtr hwndParent) {
			var childScreenCoord = new NativePoint();

			TabbedThumbnailNativeMethods.ClientToScreen(hwnd, ref childScreenCoord);

			var parentScreenCoord = new NativePoint();

			TabbedThumbnailNativeMethods.ClientToScreen(hwndParent, ref parentScreenCoord);

			System.Drawing.Point offset = new System.Drawing.Point(
				childScreenCoord.X - parentScreenCoord.X,
				childScreenCoord.Y - parentScreenCoord.Y);

			return offset;
		}
Esempio n. 26
0
        /// <summary>
        ///     Implementation like <a href="https://msdn.microsoft.com/en-us/library/6d7ws9s4(v=vs.110).aspx">Screen.GetBounds</a>
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public static NativeRect GetBounds(NativePoint point)
        {
            DisplayInfo returnValue = null;

            foreach (var display in AllDisplayInfos)
            {
                if (display.IsPrimary && returnValue == null)
                {
                    returnValue = display;
                }
                if (display.Bounds.Contains(point))
                {
                    returnValue = display;
                }
            }
            return(returnValue?.Bounds ?? NativeRect.Empty);
        }
Esempio n. 27
0
        /// <summary>
        ///     This method is called on a DrawableContainers when:
        ///     1) The capture on the surface is modified in such a way, that the elements would not be placed correctly.
        ///     2) Currently not implemented: an element needs to be moved, scaled or rotated.
        ///     This basis implementation makes sure the coordinates of the element, including the TargetGripper, is correctly
        ///     rotated/scaled/translated.
        ///     But this implementation doesn't take care of any changes to the content!!
        /// </summary>
        /// <param name="matrix"></param>
        public virtual void Transform(Matrix matrix)
        {
            if (matrix == null)
            {
                return;
            }
            var topLeft     = new NativePoint(Left, Top);
            var bottomRight = new NativePoint(Left + Width, Top + Height);

            Point[] points = { topLeft, bottomRight };
            matrix.TransformPoints(points);

            Left   = points[0].X;
            Top    = points[0].Y;
            Width  = points[1].X - points[0].X;
            Height = points[1].Y - points[0].Y;
        }
Esempio n. 28
0
        /// <summary>
        ///     Create an animation for the zoomer, depending on if it's active or not.
        /// </summary>
        private void InitializeZoomer(bool isOn)
        {
            if (isOn)
            {
                var screenBounds = DisplayInfo.GetBounds(MousePosition);
                var zoomerSize   = CalculateZoomSize(screenBounds);

                var initialPosition = new NativePoint(20, 20);
                // Initialize the zoom with an initial position
                _zoomAnimator = new RectangleAnimator(new NativeRect(initialPosition, NativeSize.Empty), new NativeRect(initialPosition, zoomerSize), FramesForMillis(1000), EasingTypes.Quintic, EasingModes.EaseOut);
                VerifyZoomAnimation(_cursorPos, false);
            }
            else
            {
                _zoomAnimator?.ChangeDestination(new NativeRect(NativePoint.Empty, NativeSize.Empty), FramesForMillis(1000));
            }
        }
Esempio n. 29
0
        private DocumentContainer(IHTMLWindow2 frameWindow, IInteropWindow contentWindow, DocumentContainer parent)
        {
            var document2 = GetDocumentFromWindow(frameWindow);

            try
            {
                Log.Debug().WriteLine("frameWindow.name {0}", frameWindow.name);
                Name = frameWindow.name;
            }
            catch
            {
                // Ignore
            }
            try
            {
                Log.Debug().WriteLine("document2.url {0}", document2.url);
            }
            catch
            {
                // Ignore
            }
            try
            {
                Log.Debug().WriteLine("document2.title {0}", document2.title);
            }
            catch
            {
                // Ignore
            }

            Parent = parent;
            // Calculate startLocation for the frames
            var         window2 = document2.parentWindow;
            var         window3 = (IHTMLWindow3)window2;
            NativePoint contentWindowLocation = contentWindow.GetInfo().Bounds.Location;
            var         x = window3.screenLeft - contentWindowLocation.X;
            var         y = window3.screenTop - contentWindowLocation.Y;

            // Release IHTMLWindow 2+3 com objects
            ReleaseCom(window2);
            ReleaseCom(window3);

            _startLocation = new NativePoint(x, y);
            Init(document2, contentWindow);
        }
Esempio n. 30
0
        /// <summary>
        ///     This creates the capture form
        /// </summary>
        /// <param name="coreConfiguration">ICoreConfiguration</param>
        /// <param name="capture">ICapture</param>
        /// <param name="windows">IList of IInteropWindow</param>
        public CaptureForm(ICoreConfiguration coreConfiguration, ICapture capture, IList <IInteropWindow> windows) : base(coreConfiguration, null)
        {
            _coreConfiguration   = coreConfiguration;
            _isZoomerTransparent = _coreConfiguration.ZoomerOpacity < 1;
            ManualLanguageApply  = true;
            ManualStoreFields    = true;

            // Enable the AnimatingForm
            EnableAnimation = true;

            _capture        = capture;
            _windows        = windows;
            UsedCaptureMode = capture.CaptureDetails.CaptureMode;

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            Text = "Greenshot capture form";

            // Log at close
            if (Log.IsDebugEnabled())
            {
                FormClosing += (s, e) => Log.Debug().WriteLine("Closing captureform");
            }

            // set cursor location
            _cursorPos = _mouseMovePos = WindowCapture.GetCursorLocationRelativeToScreenBounds();

            // Initialize the animations, the window capture zooms out from the cursor to the window under the cursor
            if (UsedCaptureMode == CaptureMode.Window)
            {
                _windowAnimator = new RectangleAnimator(new NativeRect(_cursorPos, NativeSize.Empty), _captureRect, FramesForMillis(700), EasingTypes.Quintic, EasingModes.EaseOut);
            }

            // Set the zoomer animation
            InitializeZoomer(_coreConfiguration.ZoomerEnabled);

            Bounds = capture.ScreenBounds;

            // Fix missing focus
            ToFront = true;
            TopMost = true;
        }
Esempio n. 31
0
        private void Test_NativePoint_TypeConverter()
        {
            var nativePoint = new NativePoint(123, 456);

            var typeConverter = TypeDescriptor.GetConverter(typeof(NativePoint));

            Assert.NotNull(typeConverter);
            var stringRepresentation = typeConverter.ConvertToInvariantString(nativePoint);

            Assert.Equal("123,456", stringRepresentation);
            var nativePointResult = (NativePoint?)typeConverter.ConvertFromInvariantString(stringRepresentation);

            Assert.True(nativePointResult.HasValue);
            if (nativePointResult.HasValue)
            {
                Assert.Equal(nativePoint, nativePointResult.Value);
            }
        }
Esempio n. 32
0
        /// <summary>
        ///     Corrent the frame locations with the information
        /// </summary>
        /// <param name="frameElement"></param>
        private void CorrectFrameLocations(IHTMLElement frameElement)
        {
            long         x          = 0;
            long         y          = 0;
            var          element    = frameElement;
            IHTMLElement oldElement = null;

            do
            {
                x      += element.offsetLeft;
                y      += element.offsetTop;
                element = element.offsetParent;
                // Release element, but prevent the frameElement to be released
                if (oldElement != null)
                {
                    ReleaseCom(oldElement);
                }
                oldElement = element;
            } while (element != null);

            var elementLocation         = new NativePoint((int)x, (int)y);
            var element2                = (IHTMLElement2)frameElement;
            var rec                     = element2.getBoundingClientRect();
            var elementBoundingLocation = new NativePoint(rec.left, rec.top);

            // Release IHTMLRect
            ReleaseCom(rec);
            Log.Debug().WriteLine("Looking for iframe to correct at {0}", elementBoundingLocation);
            foreach (var foundFrame in Frames)
            {
                var frameLocation = foundFrame.SourceLocation;
                if (frameLocation.Equals(elementBoundingLocation))
                {
                    // Match found, correcting location
                    Log.Debug().WriteLine("Correcting frame from {0} to {1}", frameLocation, elementLocation);
                    foundFrame.SourceLocation      = elementLocation;
                    foundFrame.DestinationLocation = elementLocation;
                }
                else
                {
                    Log.Debug().WriteLine("{0} != {1}", frameLocation, elementBoundingLocation);
                }
            }
        }
Esempio n. 33
0
        /// <summary>
        ///     Get a location where this window would be visible
        ///     * if none is found return false, formLocation = the original location
        ///     * if something is found, return true and formLocation = new location
        /// </summary>
        /// <param name="interopWindow">IInteropWindow, the window to find a location for</param>
        /// <param name="formLocation">NativePoint with the location where the window will fit</param>
        /// <returns>true if a location if found, and the formLocation is also set</returns>
        public static bool GetVisibleLocation(this IInteropWindow interopWindow, out NativePoint formLocation)
        {
            bool doesWindowFit   = false;
            var  windowRectangle = interopWindow.GetInfo().Bounds;

            // assume own location
            formLocation = windowRectangle.Location;
            var primaryDisplay = DisplayInfo.AllDisplayInfos.First(x => x.IsPrimary);

            using (var workingArea = new Region(primaryDisplay.Bounds))
            {
                // Create a region with the screens working area
                foreach (var display in DisplayInfo.AllDisplayInfos)
                {
                    if (!display.IsPrimary)
                    {
                        workingArea.Union(display.Bounds);
                    }
                }

                // If the formLocation is not inside the visible area
                if (!workingArea.AreRectangleCornersVisisble(windowRectangle))
                {
                    // If none found we find the biggest screen
                    foreach (var display in DisplayInfo.AllDisplayInfos)
                    {
                        var newWindowRectangle = new Rectangle(display.WorkingArea.Location, windowRectangle.Size);
                        if (!workingArea.AreRectangleCornersVisisble(newWindowRectangle))
                        {
                            continue;
                        }
                        formLocation  = display.Bounds.Location;
                        doesWindowFit = true;
                        break;
                    }
                }
                else
                {
                    doesWindowFit = true;
                }
            }
            return(doesWindowFit);
        }
Esempio n. 34
0
 public static extern int ScreenToClient(IntPtr hWnd, ref NativePoint pt);
Esempio n. 35
0
 public static extern int DwmSetIconicLivePreviewBitmap(
     IntPtr hwnd,
     IntPtr hbitmap,
     ref NativePoint ptClient,
     uint flags);
Esempio n. 36
0
 public static extern bool GetCursorPos(ref NativePoint point);