ideallove

ideallove

WinUI3/WPF ウィンドウの透過性を実現する

  1. 背景を透明に設定します。

// Windows App SDK 1.5 / WinUI3 用
private const int WS_EX_TRANSPARENT = 0x00000020;
private const int GWL_EXSTYLE = -20;
private const int GWL_STYLE = -16;

[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
// ページの起動時に
IntPtr hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
int extendedStyle = GetWindowLong(hwnd, GWL_STYLE);
_ = SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
//_ = SetWindowLong(hwnd, GWL_EXSTYLE, 0x80020); // 0x80020 でウィンドウの透明化が可能です
// WPF 用
private const int WS_EX_TRANSPARENT = 0x00000020;
private const int GWL_EXSTYLE = -20;

[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
// ページの起動時に
IntPtr hwnd = System.Windows.Interop.WindowInteropHelper(this).Handle;
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
_ = SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。