From 0f95009a00d081dbc4680ff7734300957a354a96 Mon Sep 17 00:00:00 2001 From: cetcjinjian Date: Thu, 4 May 2023 20:40:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=BD=E9=87=91?= =?UTF-8?q?=E8=AF=81=E5=88=B8=E4=B8=8B=E5=8D=95=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=8E=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thsauto.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/thsauto.py b/thsauto.py index 3d618ba..fe024c8 100644 --- a/thsauto.py +++ b/thsauto.py @@ -20,7 +20,7 @@ refresh_sleep_time = 0.5 retry_time = 10 -window_title = u'网上股票交易系统5.0' +window_title = u'国金全能行远航版' def get_clipboard_data(): win32clipboard.OpenClipboard() @@ -135,14 +135,24 @@ def handler(hwnd, results): return False enum_children(hwnd, results) return len(results) == 0 + + def callback1(hwnd, _): + if win32gui.GetClassName(hwnd) == "#32770": + windows.append(hwnd) + return True + + def callback2(hwnd, _): + if win32gui.GetClassName(hwnd) == "Static": + windows.append(hwnd) + return True + + windows = [] + win32gui.EnumWindows(callback1, None) + for window in windows: + win32gui.EnumChildWindows(window, callback2, None) + - popups = [] - windows = [] - win32gui.EnumThreadWindows(tid, lambda hwnd, l: l.append(hwnd), windows) - for hwnd in windows: - if not handler(hwnd, popups): - break - for ctrl in popups: + for ctrl in windows: text = get_text(ctrl) if u"检测到您正在拷贝数据" in text: return ctypes.windll.user32.GetWindow(ctrl, win32con.GW_HWNDNEXT) @@ -162,6 +172,13 @@ def get_balance(self): 'code': 0, 'status': 'succeed', 'data': data, } + + def empty_clipboard(self): + win32clipboard.OpenClipboard() + try: + win32clipboard.EmptyClipboard() + finally: + win32clipboard.CloseClipboard() def get_position(self): self.switch_to_normal() @@ -172,9 +189,9 @@ def get_position(self): ctrl = win32gui.GetDlgItem(hwnd, 0x417) self.copy_table(ctrl) - data = None retry = 0 + #self.empty_clipboard() while not data and retry < retry_time: retry += 1 time.sleep(sleep_time) @@ -518,6 +535,7 @@ def copy_table(self, hwnd): win32gui.SetForegroundWindow(hwnd) os.system('echo off | clip') hot_key(['ctrl', 'c']) + time.sleep(0.2) self.input_ocr() def input_ocr(self): @@ -535,8 +553,8 @@ def input_ocr(self): def capture_window(self, hwnd, file_name): left, top, right, bottom = win32gui.GetWindowRect(hwnd) - width = right - left - height = bottom - top + width = right - left + 40 + height = bottom - top + 10 hdc = win32gui.GetWindowDC(hwnd) dc = win32ui.CreateDCFromHandle(hdc)