public WinUICompositedWindow CreateWindow(IntPtr hWnd) { using var sc = _syncContext.EnsureLocked(); using var desktopTarget = _compositorDesktopInterop.CreateDesktopWindowTarget(hWnd, 0); using var target = desktopTarget.QueryInterface <ICompositionTarget>(); using var drawingSurface = _device.CreateDrawingSurface(new UnmanagedMethods.SIZE(), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using var surface = drawingSurface.QueryInterface <ICompositionSurface>(); using var surfaceInterop = drawingSurface.QueryInterface <ICompositionDrawingSurfaceInterop>(); using var surfaceBrush = _compositor.CreateSurfaceBrushWithSurface(surface); using var brush = surfaceBrush.QueryInterface <ICompositionBrush>(); using var spriteVisual = _compositor.CreateSpriteVisual(); spriteVisual.SetBrush(brush); using var visual = spriteVisual.QueryInterface <IVisual>(); using var visual2 = spriteVisual.QueryInterface <IVisual2>(); using var container = _compositor.CreateContainerVisual(); using var containerVisual = container.QueryInterface <IVisual>(); using var containerVisual2 = container.QueryInterface <IVisual2>(); containerVisual2.SetRelativeSizeAdjustment(new Vector2(1, 1)); using var containerChildren = container.Children; target.SetRoot(containerVisual); using var blur = CreateBlurVisual(); containerChildren.InsertAtTop(blur); containerChildren.InsertAtTop(visual); return(new WinUICompositedWindow(_syncContext, _compositor, _pumpLock, target, surfaceInterop, visual, blur)); }
// Create window and content protected override HandleRef BuildWindowCore(HandleRef hwndParent) { // Create Window. HwndHost = User32.CreateWindowExW( dwExStyle: 0, lpClassName: "Message", lpWindowName: "CompositionHost", dwStyle: User32.WS.WS_CHILD, x: 0, y: 0, nWidth: 0, nHeight: 0, hWndParent: hwndParent.Handle, hMenu: IntPtr.Zero, hInstance: IntPtr.Zero, lpParam: IntPtr.Zero); // Get compositor and target for hwnd. _compositorDesktopInterop.CreateDesktopWindowTarget(HwndHost, true, out _compositionTarget); return(new HandleRef(this, HwndHost)); }