ek-ui 0.9.9

ek 生态常驻主界面(egui/eframe):插件即界面——观测页 + 日志页,车头与 UI 同插件
Documentation
param([int]$Hwnd = 0, [string]$Out = "$env:TEMP\ek-layout\v5audit1.png")
Add-Type -AssemblyName System.Drawing
if (-not $Hwnd) {
    $p = Get-Process ek-ui -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 } | Select-Object -First 1
    if (-not $p) { Write-Output "NO WINDOW"; exit 1 }
    $Hwnd = $p.MainWindowHandle
}
$sig = @'
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
'@
$u = Add-Type -MemberDefinition $sig -Name Win32 -Namespace EkCap -PassThru |
    Where-Object { $_.Name -eq 'Win32' }
$r = New-Object EkCap.Win32+RECT
[void]$u::SetForegroundWindow([IntPtr]$Hwnd)
Start-Sleep -Seconds 1
for ($i = 0; $i -lt 6; $i++) {
    [void]$u::GetWindowRect([IntPtr]$Hwnd, [ref]$r)
    if ($r.Right - $r.Left -gt 100) { break }
    Start-Sleep -Seconds 2
}
$w = $r.Right - $r.Left; $h = $r.Bottom - $r.Top
Write-Output "rect L=$($r.Left) T=$($r.Top) W=$w H=$h"
if ($w -lt 100) { Write-Output "BAD RECT"; exit 1 }
$bmp = New-Object System.Drawing.Bitmap $w, $h
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.CopyFromScreen($r.Left, $r.Top, 0, 0, (New-Object System.Drawing.Size $w, $h))
$bmp.Save($Out)
$g.Dispose(); $bmp.Dispose()
Write-Output "saved=$Out"