Last active
March 6, 2024 03:49
-
-
Save Tiberriver256/ebd2448fd17864d87eb043923e86364c to your computer and use it in GitHub Desktop.
Make any window transparent using PowerShell. Modified from https://gist.github.com/grenade/ed8dd77ae8eeb5b4a3c1cfd66e9c8ae7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$user32 = Add-Type -Name 'user32' -Namespace 'Win32' -PassThru -MemberDefinition @' | |
[DllImport("user32.dll")] | |
public static extern int GetWindowLong(IntPtr hWnd, int nIndex); | |
[DllImport("user32.dll")] | |
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); | |
[DllImport("user32.dll", SetLastError = true)] | |
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, int bAlpha, uint dwFlags); | |
'@ | |
<# | |
.SYNOPSIS | |
This function can be used to change the transparency of any window provided it has a mainwindowhandle on the process. | |
.PARAMETER Process | |
Process name you would like to modify transparency on. | |
.PARAMETER Transparency | |
This is a number between 0 and 255. 0 is completely transparent and 255 is completely opaque. | |
.EXAMPLE | |
C:\PS> Get-Process winword.exe | % { Set-Transparency -Process $_ -Transparency 128 } | |
#> | |
function Set-Transparency { | |
param([string]$Process, [int]$transparency = 200) | |
Get-Process $Process | ? { $_.MainWindowHandle -ne 0 } | ForEach-Object { | |
$wl = $user32::GetWindowLong($_.MainWindowHandle, -20) | |
$user32::SetWindowLong($_.MainWindowHandle, -20, ($wl -bor 0x80000)) | Out-Null | |
$user32::SetLayeredWindowAttributes($_.MainWindowHandle, 0, $transparency, 0x02) | Out-Null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment