Skip to content

Commit eeb6c0d

Browse files
committed
Try fix window minimization
1 parent 895d022 commit eeb6c0d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

scripts/utils/Minimize.ps1

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ function Minimize-Window {
99
Write-Host "Starting window minimization process..." -ForegroundColor Cyan
1010
Write-Host "Looking for windows with title containing: '$windowTitlePart'" -ForegroundColor Cyan
1111

12-
# Get the handle of the current process
13-
$currentProcess = Get-Process -Id $PID
14-
$currentProcessHandle = $currentProcess.MainWindowHandle
12+
# Add the necessary Win32 API function
13+
Add-Type @"
14+
using System;
15+
using System.Runtime.InteropServices;
16+
public class Win32 {
17+
[DllImport("user32.dll")]
18+
[return: MarshalAs(UnmanagedType.Bool)]
19+
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
20+
}
21+
"@
1522

1623
# Get all open windows
1724
$windows = Get-Process | Where-Object { $_.MainWindowHandle -ne 0 }
@@ -28,13 +35,8 @@ function Minimize-Window {
2835

2936
# Minimize the window
3037
try {
31-
[void][System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(
32-
[System.Runtime.InteropServices.Marshal]::GetProcAddress(
33-
[System.Runtime.InteropServices.Marshal]::GetHINSTANCE([System.Reflection.Assembly]::GetExecutingAssembly().GetModules()[0]),
34-
"ShowWindow"
35-
),
36-
[System.IntPtr]
37-
)($window.MainWindowHandle, 2) # 2 = SW_MINIMIZE
38+
# SW_MINIMIZE = 6
39+
[Win32]::ShowWindow($window.MainWindowHandle, 6)
3840
Write-Host "Successfully minimized window: $($window.MainWindowTitle)" -ForegroundColor Green
3941
$matchFound = $true
4042
}

0 commit comments

Comments
 (0)