Ejemplo n.º 1
0
        public void StartRender(IntPtr hWnd, int x, int y, int width, int height)
        {
            _srcWindowHandle = hWnd;
            _clientX         = x;
            _clientY         = y;
            _clientWidth     = width;
            _clientHeight    = height;

            // 1st, change DirectX rendering size and register composition event.
            _dxImage.Dispatcher.Invoke(() =>
            {
                _dxImage.SetPixelSize(_windowWidth, _windowHeight);
                CompositionTarget.Rendering += CompositionTargetOnRendering;
            });

            // 2nd, find WorkerW and send 0x052C (undocumented) message to progman
            var workerW = FindWorkerW();

            if (workerW == IntPtr.Zero)
            {
                Debug.WriteLine("WARNING: Unknown desktop structure"); // SHELLDLL_DefView だとか WorkerW なくても動くが、ログだけ残しとく
            }
            var progman = NativeMethods.FindWindow("Progman", null);

            // 3rd, stick myself to progman
            NativeMethods.SetParent(_hWnd, workerW != IntPtr.Zero ? workerW : progman);

            // 4th, move self to rendering position
            NativeMethods.MoveWindow(_hWnd, _windowX, _windowY, _windowWidth, _windowHeight, true);
        }
Ejemplo n.º 2
0
        private void Img_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double dpiScale = 1.0; // default value for 96 dpi

            // determine DPI
            // (as of .NET 4.6.1, this returns the DPI of the primary monitor, if you have several different DPIs)
            if (PresentationSource.FromVisual(this).CompositionTarget is HwndTarget hwndTarget)
            {
                dpiScale = hwndTarget.TransformToDevice.M11;
            }

            int surfWidth  = (int)(host.ActualWidth < 0 ? 0 : Math.Ceiling(host.ActualWidth * dpiScale));
            int surfHeight = (int)(host.ActualHeight < 0 ? 0 : Math.Ceiling(host.ActualHeight * dpiScale));

            // Notify the D3D11Image of the pixel size desired for the DirectX rendering.
            // The D3DRendering component will determine the size of the new surface it is given, at that point.
            d3dImage.SetPixelSize(surfWidth, surfHeight);
        }