mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-05-10 00:02:09 +00:00
Fix null window handle to prevent GetWindowRect error (#3279)
This commit is contained in:
parent
cdd601d7da
commit
fbd2423d19
@ -351,6 +351,9 @@ Add-Type @"
|
|||||||
"@
|
"@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Initialize window handle with a default value
|
||||||
|
$windowHandle = [System.IntPtr]::Zero
|
||||||
|
|
||||||
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
|
foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) {
|
||||||
# Check if the process's MainWindowHandle is valid
|
# Check if the process's MainWindowHandle is valid
|
||||||
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) {
|
||||||
@ -358,11 +361,12 @@ Add-Type @"
|
|||||||
$windowHandle = $proc.MainWindowHandle
|
$windowHandle = $proc.MainWindowHandle
|
||||||
} else {
|
} else {
|
||||||
Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)"
|
Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$rect = New-Object RECT
|
$rect = New-Object RECT
|
||||||
|
# Call GetWindowRect only if a valid window handle is present
|
||||||
|
if ($windowHandle -ne [System.IntPtr]::Zero) {
|
||||||
[Window]::GetWindowRect($windowHandle, [ref]$rect)
|
[Window]::GetWindowRect($windowHandle, [ref]$rect)
|
||||||
$width = $rect.Right - $rect.Left
|
$width = $rect.Right - $rect.Left
|
||||||
$height = $rect.Bottom - $rect.Top
|
$height = $rect.Bottom - $rect.Top
|
||||||
@ -392,6 +396,9 @@ Add-Type @"
|
|||||||
} else {
|
} else {
|
||||||
Write-Debug "Unable to retrieve information about the primary monitor."
|
Write-Debug "Unable to retrieve information about the primary monitor."
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Write-Debug "No valid window handle found for window positioning."
|
||||||
|
}
|
||||||
|
|
||||||
Invoke-WPFTab "WPFTab1BT"
|
Invoke-WPFTab "WPFTab1BT"
|
||||||
$sync["Form"].Focus()
|
$sync["Form"].Focus()
|
||||||
|
Loading…
Reference in New Issue
Block a user