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

1_8.png

 

Alla fine del tutorial la vostra finestra sarà così:

2_9.png

 

Bene, cominciamo. Innanzitutto aggiungete al vostro progetto un modulo e chiamatelo GlassHelper

addmodulo.png

glasshelper.png

 

Ora aggiungete questo codice in GlassHelper prima dell'inizio del modulo.

 

  1. Imports System.Runtime.InteropServices
  2. Imports System.Windows.Interop
  3.  
  4. <StructLayout(LayoutKind.Sequential)> _
  5. Public Structure MARGINS
  6.     Public Sub New(ByVal t As Thickness)
  7.         Left = CInt(t.Left)
  8.         Right = CInt(t.Right)
  9.         Top = CInt(t.Top)
  10.         Bottom = CInt(t.Bottom)
  11.     End Sub
  12.     Public Left As Integer
  13.     Public Right As Integer
  14.     Public Top As Integer
  15.     Public Bottom As Integer
  16. End Structure
    Infine 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

 

  1. Module GlassHelper
  2.     <DllImport("dwmapi.dll")> _
  3.     Public Function DwmExtendFrameIntoClientArea(hWnd As IntPtr, ByRef pMargins As MARGINS) As Integer
  4.     End Function
  5.  
  6.     <DllImport("dwmapi.dll", PreserveSig:=False)> _
  7.     Public Function DwmIsCompositionEnabled() As Boolean
  8.     End Function
  9.  
  10.  
  11.     Public ReadOnly Property IsDwmCompositionAvailable() As Boolean
  12.         Get
  13.             'Vista è la versione 6. Non usare l'effetto Aero se minore poiché dwmapi.dll non esiste
  14.            Return Environment.OSVersion.Version.Major >= 6
  15.         End Get
  16.     End Property
  17.  
  18.     Public ReadOnly Property IsDwmCompositionEnabled() As Boolean
  19.         Get
  20.             ' Assicurarsi che mdwapi.dll sia presente, altrimenti, chiamare DwmIsCompositionEnable genererà un errore.
  21.            If Not IsDwmCompositionAvailable Then
  22.                 Return False
  23.             End If
  24.             Return DwmIsCompositionEnabled()
  25.         End Get
  26.     End Property
  27.  
  28.     Public Function ExtendGlassFrame(ByVal window As Window, ByVal margin As Thickness) As Boolean
  29.         If Not DwmIsCompositionEnabled() Then
  30.             Return False
  31.         End If
  32.         If Environment.OSVersion.Version.Major >= 6 Then
  33.         Else
  34.             Return False
  35.         End If
  36.  
  37.         Dim hwnd As IntPtr = New WindowInteropHelper(window).Handle
  38.         If hwnd = IntPtr.Zero Then
  39.             Throw New InvalidOperationException("The Window must be shown before extending glass.")
  40.         End If
  41.  
  42.         'Imposta il background a trasaprente ad entramble le prospettive WPF e Win32
  43.        window.Background = Brushes.Transparent
  44.         HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent
  45.  
  46.         Dim margins As New MARGINS(margin)
  47.         DwmExtendFrameIntoClientArea(hwnd, margins)
  48.         Return True
  49.     End Function
  50.  
  51. End Module

 

59

 

Ecco in allegato il progetto nel caso non abbiate capito qualcosa

http://uploading.com/mb5m3c9e/Example-Aeroglass-WPF-zip