Exemplo n.º 1
0
        /// <summary>
        ///     Makes a transparent window which adjust it's size and position to fit the parent window
        /// </summary>
        /// <param name="parent">HWND/Handle of a window</param>
        /// <param name="limitFps">VSync</param>
        /// <exception cref="Exception">
        ///     The handle of the parent window isn't valid
        ///     or
        ///     Could not create OverlayWindow
        /// </exception>
        public DirectXOverlayWindow(IntPtr parent, bool limitFps = true)
        {
            if (parent == IntPtr.Zero)
            {
                throw new Exception("The handle of the parent window isn't valid");
            }

            NativeUtils.GetWindowRect(parent, out var bounds);

            IsDisposing = false;
            IsVisible   = true;
            IsTopMost   = true;

            ParentWindowExists = true;

            X = bounds.Left;
            Y = bounds.Top;

            Width  = bounds.Right - bounds.Left;
            Height = bounds.Bottom - bounds.Top;

            ParentWindow = parent;

            if (!CreateWindow())
            {
                throw new Exception("Could not create OverlayWindow");
            }

            Graphics = new Direct2DRenderer(Handle, limitFps);

            SetBounds(X, Y, Width, Height);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resize and set new position if the parent window's bounds change
        /// </summary>
        public void Update()
        {
            if (!ParentWindowExists)
            {
                return;
            }

            NativeUtils.GetWindowRect(ParentWindow, out var bounds);

            if (X != bounds.Left || Y != bounds.Top || Width != bounds.Right - bounds.Left ||
                Height != bounds.Bottom - bounds.Top)
            {
                SetBounds(bounds.Left, bounds.Top, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
            }
        }
        public void Highlight()
        {
            IntPtr windowDC;
            RECT   windowRect = new RECT(0, 0, 0, 0);

            NativeUtils.GetWindowRect(detectedWindow, ref windowRect);

            IntPtr parentWindow = NativeUtils.GetParent(detectedWindow);

            windowDC = NativeUtils.GetWindowDC(detectedWindow);
            if (windowDC != IntPtr.Zero)
            {
                Graphics graph = Graphics.FromHdc(windowDC, detectedWindow);
                graph.DrawRectangle(drawPen, 1, 1, windowRect.Width - 2, windowRect.Height - 2);
                graph.Dispose();
                NativeUtils.ReleaseDC(detectedWindow, windowDC);
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="Direct2DRenderer" /> class.
        /// </summary>
        /// <param name="hwnd">The HWND.</param>
        /// <param name="limitFps">if set to <c>true</c> [limit FPS].</param>
        public Direct2DRenderer(IntPtr hwnd, bool limitFps)
        {
            factory = new SharpDX.Direct2D1.Factory();

            fontFactory = new Factory();

            NativeUtils.GetWindowRect(hwnd, out var bounds);

            var targetProperties = new HwndRenderTargetProperties {
                Hwnd           = hwnd,
                PixelSize      = new Size2(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top),
                PresentOptions = limitFps ? PresentOptions.None : PresentOptions.Immediately
            };

            var prop = new RenderTargetProperties(RenderTargetType.Hardware,
                                                  new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None,
                                                  FeatureLevel.Level_DEFAULT);

            device = new WindowRenderTarget(factory, prop, targetProperties)
            {
                TextAntialiasMode = TextAntialiasMode.Aliased,
                AntialiasMode     = AntialiasMode.Aliased
            };
        }