Skip to content

Commit 6a36d7b

Browse files
committed
Handle transparent rendering in WPF.
1 parent 871aabb commit 6a36d7b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Samples/Islands/WpfCalculator/CalculatorDemo/WpfIslandHost.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ protected override HandleRef BuildWindowCore(HandleRef hwndParent)
2020
_compositor,
2121
new Microsoft.UI.WindowId((ulong)hwndParent.Handle));
2222

23+
// Mark as a layered window to handle transparent HWND with WPF.
24+
var hwndChild = Win32Interop.GetWindowFromWindowId(DesktopChildSiteBridge.WindowId);
25+
int prevExStyleFlags = GetWindowLong(hwndChild, GWL_EXSTYLE);
26+
SetWindowLongPtr(
27+
hwndChild,
28+
GWL_EXSTYLE,
29+
new IntPtr(prevExStyleFlags | WS_EX_LAYERED));
30+
2331
return new HandleRef(null, (nint)DesktopChildSiteBridge.WindowId.Value);
2432
}
2533

@@ -30,5 +38,22 @@ protected override void DestroyWindowCore(HandleRef hwnd)
3038
}
3139

3240
Microsoft.UI.Composition.Compositor _compositor;
41+
42+
#region P/Invokes
43+
const int GWL_EXSTYLE = -20;
44+
const int WS_EX_LAYERED = 0x00080000;
45+
46+
[DllImport("user32.dll")]
47+
static extern int GetWindowLong(
48+
IntPtr hwnd,
49+
int index);
50+
51+
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
52+
[return: MarshalAs(UnmanagedType.Bool)]
53+
public static extern bool SetWindowLongPtr(
54+
IntPtr hWnd,
55+
int nIndex,
56+
IntPtr dwNewLong);
57+
#endregion
3358
}
34-
}
59+
}

0 commit comments

Comments
 (0)