gpt4 book ai didi

.net - 是否可以通过命令行设置 powershell 不透明度

转载 作者:行者123 更新时间:2023-12-01 07:53:02 25 4
gpt4 key购买 nike

PowerShell 和 .NET 的新手。

可以到 configure powershell 控制台颜色。

但是,如何设置窗口的不透明度。看来InternalHostRawUserInterface类的属性采用枚举 ConsoleColor .

是否可以设置窗口透明度?

最佳答案

Joey mentioned in his comment ,您将不得不与低级 API 交谈以修改窗口的透明度。

使用 this example ,我们可以像这样使它适应 PowerShell:

function Set-ConsoleOpacity
{
param(
[ValidateRange(10,100)]
[int]$Opacity
)

# Check if pinvoke type already exists, if not import the relevant functions
try {
$Win32Type = [Win32.WindowLayer]
} catch {
$Win32Type = Add-Type -MemberDefinition @'
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
'@ -Name WindowLayer -Namespace Win32 -PassThru
}

# Calculate opacity value (0-255)
$OpacityValue = [int]($Opacity * 2.56) - 1

# Grab the host windows handle
$ThisProcess = Get-Process -Id $PID
$WindowHandle = $ThisProcess.MainWindowHandle

# "Constants"
$GwlExStyle = -20;
$WsExLayered = 0x80000;
$LwaAlpha = 0x2;

if($Win32Type::GetWindowLong($WindowHandle,-20) -band $WsExLayered -ne $WsExLayered){
# If Window isn't already marked "Layered", make it so
[void]$Win32Type::SetWindowLong($WindowHandle,$GwlExStyle,$Win32Type::GetWindowLong($WindowHandle,$GwlExStyle) -bxor $WsExLayered)
}

# Set transparency
[void]$Win32Type::SetLayeredWindowAttributes($WindowHandle,0,$OpacityValue,$LwaAlpha)
}

然后像这样使用它:
Set-ConsoleOpacity -Opacity 50

然后将窗口的不透明度设置为 50%

关于.net - 是否可以通过命令行设置 powershell 不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com