level 11
首先添加引用
Imports System.Runtime.InteropServices
Imports System.Windows.Interop
2017年04月24日 04点04分
2
level 11
Structure WindowsCompostionAttributeData
Public Attribute As WindowCompositionAttribute
Public Data As IntPtr
Public SizeOfData As Integer
End Structure
Enum WindowCompositionAttribute
WCA_ACCENT_POLICY = 19
End Enum
Enum AccentState
ACCENT_DISABLED = 0
ACCENT_ENABLE_GRADIENT = 1
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2
ACCENT_ENABLE_BLURBEHIND = 3
ACCENT_INVALID_STATE = 4
End Enum
Structure AccentPolicy
Public AccentState As AccentState
Public AccentFlags As Integer
Public GradientColor As Integer
Public A***tionId As Integer
End Structure
Private Declare Function SetWindowCompositionAttribute Lib "user32.dll" (ByVal Hwnd As IntPtr, ByRef data As WindowsCompostionAttributeData) As Long
调用API
2017年04月24日 04点04分
3
level 11
Sub EnableBlur()
Dim windowHelper As New WindowInteropHelper(Me)
Dim accent As New AccentPolicy()
Dim accentStructSize = Marshal.SizeOf(accent)
accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND
Dim accentPtr = Marshal.AllocHGlobal(accentStructSize)
Marshal.StructureToPtr(accent, accentPtr, False)
Dim data As New WindowsCompostionAttributeData() With {
.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
.SizeOfData = accentStructSize,
.Data = accentPtr
}
SetWindowCompositionAttribute(windowHelper.Handle, data)
Marshal.FreeHGlobal(accentPtr)
End Sub
定义一个sub过程
然后在窗口的loaded事件里调用EnableBlur()
就可以啦
2017年04月24日 04点04分
4
level 11
另外,你得用Windows10 1607以上版本。
2017年04月24日 04点04分
6
level 11
看了楼上吧主的代码,我深深的感觉到我的代码太业余了。
2017年04月25日 04点04分
11
我还没怎么封装这个功能呢。前一阵子我把它封装成了附加属性,但是没发布出来。
2017年04月29日 03点04分