12/14/2017 - 10:29 AM


WPF 将窗口设置为透明

    public const int WS_EX_TRANSPARENT = 0x00000020;
    public const int GWL_EXSTYLE = (-20);
    public static extern int GetWindowLong(IntPtr hwnd, int index);
    public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
    public static void ToTransparentWindow(this Window x)
      x.SourceInitialized +=
            // Get this window's handle
            IntPtr hwnd = new WindowInteropHelper(x).Handle;
            // Change the extended window style to include WS_EX_TRANSPARENT
            int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
            SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);