EnumWindows简化: _enum_callback已只加QQ/TIM相关窗口(for+TXGuiFoundation+Chrome+title), for循环直接取第一个可见+尺寸正常的, 不要求标题含QQ/TIM

This commit is contained in:
youpaishidifu
2026-07-26 18:49:23 +08:00
parent efdc8b0a4c
commit 621d4c45b6
+7 -9
View File
@@ -238,21 +238,19 @@ class MessageMonitor:
cls = win32gui.GetClassName(top)
title = win32gui.GetWindowText(top)
title_upper = title.upper().strip()
# 规则A: Chrome_WidgetWin_1 → QQ NT Electron 主窗口(标题是群名/昵称,不含QQ/TIM)
if "Chrome" in cls:
# _enum_callback 只加了 QQ/TIM 相关窗口,所以 found 里都是有效候选
# 优先选标题含 QQ/TIM 的(传统模式),其次任何 TXGuiFoundation 或 Chrome 都接受
if "TIM" in title_upper:
self._app_variant[platform] = "tim"
else:
self._app_variant[platform] = "qq_nt"
self._cached_hwnd[platform] = top
self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1]
if "Chrome" in cls:
logger.info(f"[{platform}] 窗口已定位(Electron Chrome): {title} top={top}")
return top
# 规则B: 标题含 QQ/TIM → 传统 QQ / TIM 主窗口
if "QQ" in title_upper or "TIM" in title_upper:
self._app_variant[platform] = "tim" if "TIM" in title_upper else "qq_nt"
self._cached_hwnd[platform] = top
self._cached_pid[platform] = win32process.GetWindowThreadProcessId(top)[1]
else:
logger.info(f"[{platform}] 窗口已定位(Win32 Enum): {title} top={top}")
return top
logger.debug(f"[{platform}] Enum 候选跳过: cls={cls} title={title[:30]} top={top}")
except Exception:
pass
# 3. UIA 按窗口名搜索(兜底,可能慢但不挂死)