我希望最小化脚本,然后在某些条件下覆盖控制台的大小和颜色,并恢复/显示控制台。我想首先修改控制台,因为我希望用户第一次看到它与修改后的尺寸和颜色。使用下面的代码,如果我从设置为普通窗口的快捷方式启动,则调整大小按预期工作。但是如果将快捷方式设置为“开始最小化”,则调整大小不起作用,窗口宽度仅为120个字符。我尝试过各种Window风格的选择; Show,Restore& ShowNormal。一切都表现得一样。然而,颜色正在改变。 关于我在尺码上有什么不妥的想法?
function Set-WindowStyle {
param(
[Parameter()]
[ValidateSet('FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE',
'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED',
'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL')]
$state = 'MINIMIZE',
[Parameter()]$windowHandle = (Get-Process –id:$pid).mainWindowHandle
)
$windowStates = @{
'FORCEMINIMIZE' = 11
'HIDE' = 0
'MAXIMIZE' = 3
'MINIMIZE' = 6
'RESTORE' = 9
'SHOW' = 5
'SHOWDEFAULT' = 10
'SHOWMAXIMIZED' = 3
'SHOWMINIMIZED' = 2
'SHOWMINNOACTIVE' = 7
'SHOWNA' = 8
'SHOWNOACTIVATE' = 4
'SHOWNORMAL' = 1
}
$showWindow = Add-Type –memberDefinition @”
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
“@ -name:“Win32ShowWindowAsync” -namespace:Win32Functions –passThru
$showWindow::ShowWindowAsync($windowHandle, $windowStates[$state]) > $null
}
function Set-Console {
$psHost = Get-Host
$psWindow = $psHost.ui.rawui
$psWindow.CursorSize = "50"
$psHost.Ui.RawUi.ForeGroundColor = "Black"
$psHost.Ui.RawUi.BackGroundColor = "White"
$newSize = $psWindow.buffersize
$newSize.width = 140
$newSize.height = 100
$psWindow.buffersize = $newSize
$newSize = $psWindow.windowsize
$newSize.width = 140
$newSize.height = 35
$psWindow.windowsize = $newSize
Clear-Host
}
Set-Console
Write-Host '_________1_________2_________3_________4_________5_________6_________7_________8_________9________10________11________12________13________14'
Set-WindowStyle SHOWNORMAL