Example #1
0
        private void Initialize()
        {
            ShowWindow(handle, SW_SHOWNORMAL);
            ShowWindow(handle, SW_RESTORE);
            BringToFront();

            var rect = new WindowRectangle();

            GetWindowRect(handle, ref rect);

            FieldWidth  = (rect.Right - rect.Left - widthExcess) / mineSize;
            FieldHeight = (rect.Bottom - rect.Top - heightExcess) / mineSize;
            bounds      = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
            fieldBounds = new Rectangle(bounds.X + xFieldAdjust, bounds.Y + yFieldAdjust, mineSize * FieldWidth, mineSize * FieldHeight);

            cells        = new Cell[FieldWidth, FieldHeight];
            cellContents = new CellContents[FieldWidth, FieldHeight];

            for (int i = 0; i < FieldWidth; i++)
            {
                for (int j = 0; j < FieldHeight; j++)
                {
                    cells[i, j]        = Cell.Closed;
                    cellContents[i, j] = CellContents.Mine; // Kappa
                }
            }
        }
Example #2
0
        //Update the window style
        async Task UpdateWindowStyleHidden()
        {
            try
            {
                await AVActions.ActionDispatcherInvokeAsync(async delegate
                {
                    //Set the window style
                    IntPtr updatedStyle = new IntPtr((uint)WindowStyles.WS_NONE);
                    await SetWindowLongAuto(vInteropWindowHandle, (int)WindowLongFlags.GWL_STYLE, updatedStyle);

                    //Move window to force style
                    WindowRectangle positionRect = new WindowRectangle();
                    GetWindowRect(vInteropWindowHandle, ref positionRect);
                    if (vHideAdded)
                    {
                        WindowMove(vInteropWindowHandle, positionRect.Left + 1, positionRect.Top + 1);
                        vHideAdded = false;
                    }
                    else
                    {
                        WindowMove(vInteropWindowHandle, positionRect.Left - 1, positionRect.Top - 1);
                        vHideAdded = true;
                    }
                });
            }
            catch { }
        }
 public PositionedWindow(WindowRectangle rectangle, IntPtr windowHandle, string title,
                         User32.WINDOWPLACEMENT placement, bool isVisible)
 {
     Rectangle    = rectangle;
     WindowHandle = windowHandle;
     Title        = title;
     Placement    = placement;
     IsVisible    = isVisible;
 }
        /// <summary>
        /// Captures a screenshot of a window using Windows GDI
        /// </summary>
        /// <param name="handle">handle of the window to capture</param>
        /// <returns>the captured window image</returns>
        public static Image CaptureWithGDI(IntPtr handle)
        {
            FileSystem.AppendDebug("Capturing with GDI");
            Rectangle windowRect;

            if (Engine.conf.ActiveWindowTryCaptureChildren)
            {
                windowRect = new WindowRectangle(handle).CalculateWindowRectangle();
            }
            else
            {
                windowRect = NativeMethods.GetWindowRectangle(handle);
            }

            windowRect = NativeMethods.MaximizedWindowFix(handle, windowRect);

            FileSystem.AppendDebug("Window rectangle: " + windowRect.ToString());

            Image windowImage = null;

            if (Engine.conf.ActiveWindowClearBackground)
            {
                windowImage = CaptureWindowWithTransparencyGDI(handle, windowRect);
            }

            if (windowImage == null)
            {
                using (new Freeze(handle))
                {
                    windowImage = CaptureRectangle(windowRect);
                }

                if (Engine.conf.ActiveWindowCleanTransparentCorners)
                {
                    Image result = RemoveCorners(handle, windowImage, null, windowRect);
                    if (result != null)
                    {
                        windowImage = result;
                    }
                }

                if (Engine.conf.ActiveWindowIncludeShadows)
                {
                    // Draw shadow manually to be able to have shadows in every case
                    windowImage = GraphicsMgr.AddBorderShadow((Bitmap)windowImage, true);
                }

                if (Engine.conf.ShowCursor)
                {
                    DrawCursor(windowImage, windowRect.Location);
                }
            }

            return(windowImage);
        }
Example #5
0
        private void HighlightWindow(WindowRectangle candidate)
        {
            var source = CurrentOutline ?? candidate.Rectangle;

            _currentSelectedWindow = candidate;

            Title = candidate.Title;
            CurrentOutlineAnimation = new RectangleAnimation(
                DateTime.Now,
                TimeSpan.FromMilliseconds(100),
                source,
                candidate.Rectangle
                );
        }
Example #6
0
        //Move the keyboard window based on thumb movement
        public void MoveKeyboardWindow(int mouseHorizontal, int mouseVertical)
        {
            try
            {
                //Check the mouse movement position
                if (mouseHorizontal == 0 && mouseVertical == 0)
                {
                    return;
                }

                //Get the current window position
                WindowRectangle positionRect = new WindowRectangle();
                GetWindowRect(vInteropWindowHandle, ref positionRect);
                int moveLeft   = positionRect.Left + mouseHorizontal;
                int moveTop    = positionRect.Top + mouseVertical;
                int moveRight  = positionRect.Right + mouseHorizontal;
                int moveBottom = positionRect.Bottom + mouseVertical;

                //Get the current active screen
                int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor"));
                DisplayMonitorSettings displayMonitorSettings = GetScreenSettings(monitorNumber);

                //Get the current window size
                int windowWidth  = (int)(this.ActualWidth * displayMonitorSettings.DpiScaleHorizontal);
                int windowHeight = (int)(this.ActualHeight * displayMonitorSettings.DpiScaleVertical);

                //Check if window leaves screen
                double screenEdgeLeft    = moveLeft + windowWidth;
                double screenLimitLeft   = displayMonitorSettings.BoundsLeft + 20;
                double screenEdgeTop     = moveTop + windowHeight;
                double screenLimitTop    = displayMonitorSettings.BoundsTop + 20;
                double screenEdgeRight   = moveRight - windowWidth;
                double screenLimitRight  = displayMonitorSettings.BoundsRight - 20;
                double screenEdgeBottom  = moveBottom - windowHeight;
                double screenLimitBottom = displayMonitorSettings.BoundsBottom - 20;
                if (screenEdgeLeft > screenLimitLeft && screenEdgeTop > screenLimitTop && screenEdgeRight < screenLimitRight && screenEdgeBottom < screenLimitBottom)
                {
                    WindowMove(vInteropWindowHandle, moveLeft, moveTop);
                }
            }
            catch { }
        }
Example #7
0
 private static extern bool GetWindowRect(IntPtr hwnd, ref WindowRectangle rectangle);
        /// <summary>Captures a screenshot of a window using Windows GDI. Captures transparency.</summary>
        /// <param name="handle">handle of the window to capture</param>
        /// <returns>the captured window image</returns>
        private static Image CaptureWindowWithGDI(Workflow wfgdi, IntPtr handle, out Rectangle windowRect)
        {
            Image  windowImageGdi = null;
            Bitmap whiteBGImage = null, blackBGImage = null, white2BGImage = null;

            if (wfgdi.ActiveWindowTryCaptureChildren)
            {
                windowRect = new WindowRectangle(handle).CalculateWindowRectangle();
            }
            else
            {
                windowRect = CaptureHelpers.GetWindowRectangle(handle);
            }

            try
            {
                using (new Freeze(wfgdi, handle))
                    using (Form form = new Form())
                    {
                        form.BackColor       = Color.White;
                        form.FormBorderStyle = FormBorderStyle.None;
                        form.ShowInTaskbar   = false;

                        int offset = wfgdi.ActiveWindowIncludeShadows && !NativeMethods.IsWindowMaximized(handle) ? 20 : 0;

                        windowRect.Inflate(offset, offset);
                        windowRect.Intersect(CaptureHelpers.GetScreenBounds());

                        NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNormalNoActivate);
                        NativeMethods.SetWindowPos(form.Handle, handle, windowRect.X, windowRect.Y, windowRect.Width, windowRect.Height, NativeMethods.SWP_NOACTIVATE);
                        Application.DoEvents();

                        whiteBGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect);

                        form.BackColor = Color.Black;
                        Application.DoEvents();

                        blackBGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect);

                        if (!wfgdi.ActiveWindowGDIFreezeWindow)
                        {
                            form.BackColor = Color.White;
                            Application.DoEvents();

                            white2BGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect);
                        }
                    }

                if (wfgdi.ActiveWindowGDIFreezeWindow || whiteBGImage.AreBitmapsEqual(white2BGImage))
                {
                    windowImageGdi = HelpersLib.GraphicsHelper.Core.ComputeOriginal(whiteBGImage, blackBGImage);
                }
                else
                {
                    windowImageGdi = (Image)whiteBGImage.Clone();
                }
            }
            finally
            {
                if (whiteBGImage != null)
                {
                    whiteBGImage.Dispose();
                }
                if (blackBGImage != null)
                {
                    blackBGImage.Dispose();
                }
                if (white2BGImage != null)
                {
                    white2BGImage.Dispose();
                }
            }

            if (windowImageGdi != null)
            {
                Rectangle windowRectCropped = HelpersLib.GraphicsHelper.Core.GetCroppedArea((Bitmap)windowImageGdi);
                windowImageGdi = CaptureHelpers.CropImage(windowImageGdi, windowRectCropped);

                if (wfgdi.DrawCursor)
                {
#if DEBUG
                    DebugHelper.WriteLine("Fixed cursor position (before): " + windowRect.ToString());
#endif
                    windowRect.X += windowRectCropped.X;
                    windowRect.Y += windowRectCropped.Y;
#if DEBUG
                    DebugHelper.WriteLine("Fixed cursor position (after):  " + windowRect.ToString());
#endif
                }
            }

            return(windowImageGdi);
        }
Example #9
0
 public static extern bool GetWindowRect(IntPtr hWnd, ref WindowRectangle rectangle);
Example #10
0
        /// <summary>
        /// Function to retrieve and parse the raw pointing device data.
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event data to examine.</param>
        private void GetRawData(object sender, RawInputPointingDeviceEventArgs e)
        {
            if ((BoundControl == null) || (BoundControl.Disposing))
            {
                return;
            }

            if ((_deviceHandle != IntPtr.Zero) && (_deviceHandle != e.Handle))
            {
                return;
            }

            if ((Exclusive) && (!Acquired))
            {
                // Attempt to recapture.
                if (BoundControl.Focused)
                {
                    Acquired = true;
                }
                else
                {
                    return;
                }
            }

            // Do nothing if we're outside and we have exclusive mode turned off.
            if (!Exclusive)
            {
                Point clientPosition = BoundControl.PointToClient(Cursor.Position);

                if (!WindowRectangle.Contains(clientPosition))
                {
                    _outside = true;
                    return;
                }

                if (_outside)
                {
                    // If we're back inside place position at the entry point.
                    _outside = false;
                    Position = clientPosition;
                }
            }

            // Get wheel data.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MouseWheel) != 0)
            {
                OnPointingDeviceWheelMove((short)e.PointingDeviceData.ButtonData);
            }

            // If we're outside of the delay, then restart double click cycle.
            if (_doubleClicker.Milliseconds > DoubleClickDelay)
            {
                _doubleClicker.Reset();
                _clickCount = 0;
            }

            // Get button data.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.LeftDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Left);
                OnPointingDeviceDown(PointingDeviceButtons.Left);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.RightDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Right);
                OnPointingDeviceDown(PointingDeviceButtons.Right);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MiddleDown) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Middle);
                OnPointingDeviceDown(PointingDeviceButtons.Middle);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button4Down) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Button4);
                OnPointingDeviceDown(PointingDeviceButtons.Button4);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button5Down) != 0)
            {
                BeginDoubleClick(PointingDeviceButtons.Button5);
                OnPointingDeviceDown(PointingDeviceButtons.Button5);
            }

            // If we have an 'up' event on the buttons, remove the flag.
            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.LeftUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Left))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Left, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.RightUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Right))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Right, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.MiddleUp) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Middle))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Middle, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button4Up) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Button4))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Button4, _clickCount);
            }

            if ((e.PointingDeviceData.ButtonFlags & RawMouseButtons.Button5Up) != 0)
            {
                if (IsDoubleClick(PointingDeviceButtons.Button5))
                {
                    _clickCount += 1;
                }
                else
                {
                    _doubleClicker.Reset();
                    _clickCount = 0;
                }

                OnPointingDeviceUp(PointingDeviceButtons.Button5, _clickCount);
            }

            // Fire events.
            RelativePosition = new PointF(RelativePosition.X + e.PointingDeviceData.LastX, RelativePosition.Y + e.PointingDeviceData.LastY);
            OnPointingDeviceMove(new PointF(Position.X + e.PointingDeviceData.LastX, Position.Y + e.PointingDeviceData.LastY),
                                 false);
            UpdateCursorPosition();
        }
 public RestoreNotifaction(string message, string windowTitle, string processName, WindowRectangle rectangle) : base(message, NotificationType.Information)
 {
     WindowTitle = windowTitle;
     ProcessName = processName;
     Rectangle   = rectangle;
 }
Example #12
0
 static extern bool GetWindowRect(IntPtr hWnd, out WindowRectangle lpRect);