PoshCode Logo PowerShell Code Repository

Aero Glass PowerShell by Oisin Grehan 4 years ago
View followups from semih | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2052"></script>download | new post

Enable aero “glass” effects for the regular powershell 2.0 console (not ISE) – vista or above, powershell 2+ and aero-compatible gfx card. .\glass.ps1 # turn on .\glass.ps1 -disable # turn off

  1. #requires -version 2
  2. param([switch]$Disable)
  3.  
  4. add-type -namespace Hacks -name Aero -memberdefinition @"
  5.  
  6.    [StructLayout(LayoutKind.Sequential)]
  7.    public struct MARGINS
  8.    {
  9.       public int left;
  10.       public int right;
  11.       public int top;
  12.       public int bottom;
  13.    }
  14.  
  15.    [DllImport("dwmapi.dll", PreserveSig = false)]
  16.    public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
  17.  
  18.    [DllImport("dwmapi.dll", PreserveSig = false)]
  19.    public static extern bool DwmIsCompositionEnabled();
  20. "@
  21.  
  22.  
  23. if (([Environment]::OSVersion.Version.Major -gt 5) -and
  24.      [hacks.aero]::DwmIsCompositionEnabled()) {
  25.  
  26.    $hwnd = (get-process -id $pid).mainwindowhandle
  27.  
  28.    $margin = new-object 'hacks.aero+margins'
  29.  
  30.    $host.ui.RawUI.BackgroundColor = "black"
  31.    $host.ui.rawui.foregroundcolor = "white"
  32.  
  33.    if ($Disable) {
  34.  
  35.        $margin.top = 0
  36.        $margin.left = 0
  37.  
  38.  
  39.    } else {
  40.  
  41.        $margin.top = -1
  42.        $margin.left = -1
  43.  
  44.    }
  45.  
  46.    [hacks.aero]::DwmExtendFrameIntoClientArea($hwnd, [ref]$margin)
  47.  
  48. } else {
  49.  
  50.    write-warning "Aero is either not available or not enabled on this workstation."
  51.  
  52. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me