从弹出窗口获取文本 [英] Get text from popup window

查看:39
本文介绍了从弹出窗口获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从弹出窗口中读取文本.

I'm trying to read the text from a popup window.

标题总是一样的.我已经设法识别 hwnd 并使用下面的代码获得标题,但我不知道如何阅读内容.

The title is always the same. I've managed to identify the hwnd and get the title with the code below, but I can't figure out how to read the contents.

import time

import win32gui, win32con


windows = []
def _MyCallback( hwnd, extra ):
  extra.append(hwnd)
win32gui.EnumWindows(_MyCallback, windows)

while True:
  window = win32gui.GetForegroundWindow()
  title = win32gui.GetWindowText(window)
  if title == 'Errors occurred':  print 'error window'
  time.sleep(1)

这是工作版本:

import time

import win32gui

while True:
  window = win32gui.GetForegroundWindow()
  title = win32gui.GetWindowText(window)
  if title == 'Errors occurred':
    control = win32gui.FindWindowEx(window, 0, "static", None)
    print 'text: ', win32gui.GetWindowText(control)
  time.sleep(1)

推荐答案

我无权访问您正在使用的框架或错误对话框,所以我只能概括地说您想要什么.

I don't have access to the framework or the error dialog you are using, so I can only say in general what you want.

您需要 FindWindowEx 函数,并使用它来查找类名为静态"的控件(或控件的任何类名).我想这将是这条线:

You need the FindWindowEx function, and use it to find a control whose class name is 'static' (or whatever the class name of the control is). I imagine this would be the line:

control = win32gui.FindWindowEx(window, 0, "Static", 0)

这会返回控件的句柄,然后您可以在其上使用 GetWindowText 来获取文本.

That returns the handle to the control, and you can then use GetWindowText on that to get the text.

这篇关于从弹出窗口获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆