joao678
joao678

Reputation: 21

Powershell forms full window glass transparency

I'm trying to make a powershell windows form all transparent as i was able to get the aero style controls working and hiding the powershell console window this is the only thing missing. The tutorial I was trying to implement in powershell is this: http://blogs.msdn.com/b/tims/archive/2006/04/18/578637.aspx but its in C#, help?

Upvotes: 1

Views: 1385

Answers (1)

Frode F.
Frode F.

Reputation: 54871

You could use the C# sample itself, by compiling/loading it in PowerShell. Sample (untested):

$def = @"
    [StructLayout(LayoutKind.Sequential)]
    public struct MARGINS
    {
       public int left; 
       public int right; 
       public int top; 
       public int bottom; 
    }

    [DllImport("dwmapi.dll")]
    public static extern bool DwmIsCompositionEnabled();

    [DllImport("dwmapi.dll")]
    public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
"@

#Load/Compile C# P/Invoke code
Add-Type -Namespace stackoverflow -Name Aero -MemberDefinition $def

#Check if Aero is enabled on this computer
If([stackoverflow.Aero]::DwmIsCompositionEnabled()) {

    #Get mainwindowhandle for powershell console process
    $hwnd = (Get-Process -Id $pid).MainWindowHandle

    #Define margins = how much extra space to make transparent
    $margins = New-Object -TypeName 'stackoverflow.Aero+MARGINS'
    $margins.top = 50
    $margins.bottom = 0
    $margins.left = 0
    $margins.right = 0

    #Make powershell-console partly aero.
    [stackoverflow.Aero]::DwmExtendFrameIntoClientArea($hwnd, $margins)
}

Upvotes: 2

Related Questions