# 截取 MuMu 模拟器窗口(PrintWindow,App 在虚拟副屏时依然有效) # 用法: powershell -NoProfile -File winshot.ps1 <输出png路径> param([string]$OutPath = 'C:\Users\12914\Desktop\sky\_win.png') Add-Type -AssemblyName System.Drawing Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Win32 { [DllImport("user32.dll")] public static extern bool PrintWindow(IntPtr hwnd, IntPtr hdc, uint flags); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out RECT rect); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd); [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; } } "@ $proc = Get-Process -Name MuMuNxDevice -ErrorAction Stop $hwnd = $proc.MainWindowHandle if ($hwnd -eq [IntPtr]::Zero) { throw 'MuMuNxDevice window not found' } [Win32]::ShowWindow($hwnd, 9) | Out-Null [Win32]::SetForegroundWindow($hwnd) | Out-Null Start-Sleep -Milliseconds 400 $rect = New-Object Win32+RECT [Win32]::GetWindowRect($hwnd, [ref]$rect) | Out-Null $w = $rect.Right - $rect.Left $h = $rect.Bottom - $rect.Top if ($w -le 0 -or $h -le 0) { throw "bad window rect ${w}x${h}" } $bmp = New-Object System.Drawing.Bitmap($w, $h) $g = [System.Drawing.Graphics]::FromImage($bmp) $hdc = $g.GetHdc() [Win32]::PrintWindow($hwnd, $hdc, 2) | Out-Null # PW_RENDERFULLCONTENT $g.ReleaseHdc($hdc) $g.Dispose() $bmp.Save($OutPath, [System.Drawing.Imaging.ImageFormat]::Png) $bmp.Dispose() Write-Output "saved ${w}x${h} -> $OutPath"