sky/scripts/list-mumu-windows.ps1
root 6ed55254a0 chore: initial import of sky project
Go + PostgreSQL + Valkey backend (cmd/internal/migrations),
uni-app mobile frontend, PC web (web/), admin console (admin/),
Android WebView container (android_project/).
Build artifacts, node_modules, local env and debug screenshots excluded.
2026-11-09 22:22:44 +08:00

46 lines
2.2 KiB
PowerShell

# 枚举 MuMu 相关进程的所有顶层窗口(全部逻辑在 C# 内完成)
Add-Type -TypeDefinition @"
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class WinEnum2 {
public delegate bool EnumProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc cb, IntPtr lParam);
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder sb, int max);
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetClassName(IntPtr hWnd, StringBuilder sb, int max);
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT r);
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; }
public static List<string> Results = new List<string>();
public static HashSet<uint> Pids = new HashSet<uint>();
public static void Run(uint[] pids) {
Pids = new HashSet<uint>(pids);
EnumWindows((h, l) => {
uint pid;
GetWindowThreadProcessId(h, out pid);
if (Pids.Contains(pid) && IsWindowVisible(h)) {
var t = new StringBuilder(256); GetWindowText(h, t, 256);
var c = new StringBuilder(256); GetClassName(h, c, 256);
RECT r; GetWindowRect(h, out r);
int w = r.R - r.L, hh = r.B - r.T;
if (w > 200 && hh > 200) {
Results.Add(string.Format("hwnd=0x{0:x} pid={1} class={2} title={3} size={4}x{5} pos=({6},{7})",
h.ToInt64(), pid, c, t, w, hh, r.L, r.T));
}
}
return true;
}, IntPtr.Zero);
}
}
"@
$pids = (Get-Process | Where-Object { $_.ProcessName -match 'MuMu|Nemu' }).Id | ForEach-Object { [uint32]$_ }
Write-Output ("PIDs: " + ($pids -join ','))
[WinEnum2]::Run($pids)
[WinEnum2]::Results | ForEach-Object { Write-Output $_ }
if (-not [WinEnum2]::Results.Count) { Write-Output 'NO-WINDOWS' }