📱 🔍 优化搜索功能/优化动画
This commit is contained in:
73
Util/BlurGlassUtil.cs
Normal file
73
Util/BlurGlassUtil.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
{
|
||||
public class BlurGlassUtil
|
||||
{
|
||||
internal enum AccentState
|
||||
{
|
||||
ACCENT_DISABLED = 1,
|
||||
ACCENT_ENABLE_GRADIENT = 0,
|
||||
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
|
||||
ACCENT_ENABLE_BLURBEHIND = 3,
|
||||
ACCENT_INVALID_STATE = 4
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct AccentPolicy
|
||||
{
|
||||
public AccentState AccentState;
|
||||
public int AccentFlags;
|
||||
public int GradientColor;
|
||||
public int AnimationId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct WindowCompositionAttributeData
|
||||
{
|
||||
public WindowCompositionAttribute Attribute;
|
||||
public IntPtr Data;
|
||||
public int SizeOfData;
|
||||
}
|
||||
|
||||
internal enum WindowCompositionAttribute
|
||||
{
|
||||
// ...
|
||||
WCA_ACCENT_POLICY = 19
|
||||
// ...
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
|
||||
|
||||
|
||||
public static void EnableBlur(Window window)
|
||||
{
|
||||
var windowHelper = new WindowInteropHelper(window);
|
||||
|
||||
var accent = new AccentPolicy();
|
||||
accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
|
||||
|
||||
var accentStructSize = Marshal.SizeOf(accent);
|
||||
|
||||
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
|
||||
Marshal.StructureToPtr(accent, accentPtr, false);
|
||||
|
||||
var data = new WindowCompositionAttributeData();
|
||||
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
|
||||
data.SizeOfData = accentStructSize;
|
||||
data.Data = accentPtr;
|
||||
|
||||
SetWindowCompositionAttribute(windowHelper.Handle, ref data);
|
||||
|
||||
Marshal.FreeHGlobal(accentPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user