babalae/better-genshin-impact · error · ArgumentException
游戏窗口不能最小化
Error message
游戏窗口不能最小化
What it means
Thrown by the SystemInfo constructor when User32.IsIconic(hWnd) returns true, indicating the game window is currently minimized. A minimized window cannot be captured for screen analysis, so the constructor rejects it with an ArgumentException.
Source
Thrown at BetterGenshinImpact/GameTask/Model/SystemInfo.cs:72
public int GameProcessId { get; }
public DesktopRegion DesktopRectArea { get; }
public SystemInfo(IntPtr hWnd)
{
var p = SystemControl.GetProcessByHandle(hWnd);
GameProcess = p ?? throw new ArgumentException("通过句柄获取游戏进程失败");
GameProcessName = GameProcess.ProcessName;
GameProcessId = GameProcess.Id;
DisplaySize = PrimaryScreen.WorkingArea;
DesktopRectArea = new DesktopRegion();
// 判断最小化
if (User32.IsIconic(hWnd))
{
throw new ArgumentException("游戏窗口不能最小化");
}
// 注意截图区域要和游戏窗口实际区域一致
// todo 窗口移动后?
GameScreenSize = SystemControl.GetGameScreenRect(hWnd);
if (GameScreenSize.Width < 800 || GameScreenSize.Height < 600)
{
throw new ArgumentException("游戏窗口分辨率不得小于 800x600 !");
}
// 0.28 改动,素材缩放比例不可以超过 1,也就是图像识别时分辨率大于 1920x1080 的情况下直接进行缩放
if (GameScreenSize.Width < 1920)
{
ZoomOutMax1080PRatio = GameScreenSize.Width / 1920d;
AssetScale = ZoomOutMax1080PRatio;
}
ScaleTo1080PRatio = GameScreenSize.Width / 1920d; // 1080P 为标准
View on GitHub (pinned to a7cb36712d)
Solutions
- Restore the game window from minimized state before starting any task.
- At the call site, detect minimized state and prompt the user to restore the window before constructing SystemInfo.
- Optionally call User32.ShowWindowAsync(hWnd, SW_RESTORE) to programmatically restore the window before proceeding.
- Catch ArgumentException and show a user-friendly dialog (ThemedMessageBox) asking to un-minimize the game.
Example fix
// before
if (User32.IsIconic(hWnd))
{
throw new ArgumentException("游戏窗口不能最小化");
}
// after — attempt to restore before failing
if (User32.IsIconic(hWnd))
{
User32.ShowWindowAsync(hWnd, User32.ShowWindowCommand.SW_RESTORE);
Thread.Sleep(500);
if (User32.IsIconic(hWnd))
throw new ArgumentException("游戏窗口不能最小化,请手动恢复窗口后重试");
} Defensive patterns
Strategy: validation
Validate before calling
if (User32.IsIconic(hWnd))
{
// Prompt user or attempt restore
logger.LogWarning("游戏窗口已最小化,请恢复窗口后重试");
return;
} Try / catch
try { var info = new SystemInfo(hWnd); }
catch (ArgumentException ex) when (ex.Message.Contains("最小化"))
{ /* prompt user to restore the window */ } Prevention
- Check window state before starting tasks.
- Prompt the user with ThemedMessageBox to restore the game window.
- Optionally auto-restore the window via ShowWindowAsync before constructing SystemInfo.
When it happens
Trigger: Constructing SystemInfo while the Genshin Impact game window is minimized to the taskbar. The tool requires a visible, properly-sized window to capture screenshots and compute regions.
Common situations: The user minimized the game manually; the game auto-minimized due to focus loss; another tool or overlay caused the window to minimize.
Related errors
- 游戏窗口分辨率不得小于 800x600 !
- 通过句柄获取游戏进程失败
- 动作 {snapshot.Description} 执行 {attempts} 次后,等待 {snapshot.Targ
- 鼠标限制区域必须具有有效宽度和高度。
- 临时解除本地鼠标限制失败
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/91ec0637b876ac8e.
Report an issue: GitHub.