File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,16 @@ function Minimize-Window {
9
9
Write-Host " Starting window minimization process..." - ForegroundColor Cyan
10
10
Write-Host " Looking for windows with title containing: '$windowTitlePart '" - ForegroundColor Cyan
11
11
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
+ "@
15
22
16
23
# Get all open windows
17
24
$windows = Get-Process | Where-Object { $_.MainWindowHandle -ne 0 }
@@ -28,13 +35,8 @@ function Minimize-Window {
28
35
29
36
# Minimize the window
30
37
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 )
38
40
Write-Host " Successfully minimized window: $ ( $window.MainWindowTitle ) " - ForegroundColor Green
39
41
$matchFound = $true
40
42
}
You can’t perform that action at this time.
0 commit comments