Attenzione: Ben quanto Windows 8 supporti l'utilizzo di queste librerie senza crashare, avendo abbandonato l'effetto Aeroglass non vi farà comunque visualizzare l'effetto desiderato. Mosterà invece una finestra con lo sfondo bianco.
Come detto nel titolo, qui spiegherò un semplice metodo per estendere l'effetto Aeroglass a tutta la finestra.
Innanzitutto, cos'è l'effetto Aeroglass? L'effetto aeroglass è l'effetto tipico delle finestre di Windows Vista e Windows 7
Alla fine del tutorial la vostra finestra sarà così:
Bene, cominciamo. Innanzitutto aggiungete al vostro progetto un modulo e chiamatelo GlassHelper
Ora aggiungete questo codice in GlassHelper prima dell'inizio del modulo.
-
Imports System.Runtime.InteropServices
-
Imports System.Windows.Interop
-
-
<StructLayout(LayoutKind.Sequential)> _
-
Public Structure MARGINS
-
Public Sub New(ByVal t As Thickness)
-
Left = CInt(t.Left)
-
Right = CInt(t.Right)
-
Top = CInt(t.Top)
-
Bottom = CInt(t.Bottom)
-
End Sub
-
Public Left As Integer
-
Public Right As Integer
-
Public Top As Integer
-
Public Bottom As Integer
-
End StructureInfine inserite questo codice. Innanzitutto le dichiarazioni, dopo di ché controllerà che sia tutto OK per applicare l'effetto Aeroglass (attenzione, da Windows Vista in giù non è presente l'effetto AeroGlass quindi se opportunamente gestito il programma si avvierà normalmente, altrimenti crasherà. In questo caso però si avvierà normalmente grazie ai dovuti controlli
-
Module GlassHelper
-
<DllImport("dwmapi.dll")> _
-
Public Function DwmExtendFrameIntoClientArea(hWnd As IntPtr, ByRef pMargins As MARGINS) As Integer
-
End Function
-
-
<DllImport("dwmapi.dll", PreserveSig:=False)> _
-
Public Function DwmIsCompositionEnabled() As Boolean
-
End Function
-
-
-
Public ReadOnly Property IsDwmCompositionAvailable() As Boolean
-
Get
-
'Vista è la versione 6. Non usare l'effetto Aero se minore poiché dwmapi.dll non esiste
-
Return Environment.OSVersion.Version.Major >= 6
-
End Get
-
End Property
-
-
Public ReadOnly Property IsDwmCompositionEnabled() As Boolean
-
Get
-
' Assicurarsi che mdwapi.dll sia presente, altrimenti, chiamare DwmIsCompositionEnable genererà un errore.
-
If Not IsDwmCompositionAvailable Then
-
Return False
-
End If
-
Return DwmIsCompositionEnabled()
-
End Get
-
End Property
-
-
Public Function ExtendGlassFrame(ByVal window As Window, ByVal margin As Thickness) As Boolean
-
If Not DwmIsCompositionEnabled() Then
-
Return False
-
End If
-
If Environment.OSVersion.Version.Major >= 6 Then
-
Else
-
Return False
-
End If
-
-
Dim hwnd As IntPtr = New WindowInteropHelper(window).Handle
-
If hwnd = IntPtr.Zero Then
-
Throw New InvalidOperationException("The Window must be shown before extending glass.")
-
End If
-
-
'Imposta il background a trasaprente ad entramble le prospettive WPF e Win32
-
window.Background = Brushes.Transparent
-
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent
-
-
Dim margins As New MARGINS(margin)
-
DwmExtendFrameIntoClientArea(hwnd, margins)
-
Return True
-
End Function
-
-
End Module
Ecco in allegato il progetto nel caso non abbiate capito qualcosa
http://uploading.com/mb5m3c9e/Example-Aeroglass-WPF-zip
Aggiungi un commento