From 621d4c45b6b5aa995a08329d49c458aeb67b9b9f Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 26 Jul 2026 18:49:23 +0800 Subject: [PATCH] =?UTF-8?q?EnumWindows=E7=AE=80=E5=8C=96:=20=5Fenum=5Fcall?= =?UTF-8?q?back=E5=B7=B2=E5=8F=AA=E5=8A=A0QQ/TIM=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=AA=97=E5=8F=A3(for+TXGuiFoundation+Chrome+title),=20for?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E7=9B=B4=E6=8E=A5=E5=8F=96=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=8F=AF=E8=A7=81+=E5=B0=BA=E5=AF=B8=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E7=9A=84,=20=E4=B8=8D=E8=A6=81=E6=B1=82=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E5=90=ABQQ/TIM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitor.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/monitor.py b/monitor.py index 040a5f6..114d338 100644 --- a/monitor.py +++ b/monitor.py @@ -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] + 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}") + return top except Exception: pass # 3. UIA 按窗口名搜索(兜底,可能慢但不挂死)