WindowFinder.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:myautotest 作者: auuppp 项目源码 文件源码
def get_expect_window_label_text(self, _expect_sec_window):
        '''
        Try to get window label text
        '''
#         label_text = u"????"
#         label_text = label_text.encode('utf-8')
#         return label_text
        label_text = ''
        window = self.expect_sec_window

        child_control = None
        last_child = 0
        while True:
            logging.debug("Find the child controls for parent window")
            child_control = win32gui.FindWindowEx(window, last_child, 'static', None)
            if not child_control:
                logging.debug("The child is None")
                break;
            else:
                logging.debug("The child is not None, ")
                buffer = win32gui.PyMakeBuffer(200)
                length = win32gui.SendMessage(child_control, win32con.WM_GETTEXT, 200, buffer)
                result = buffer[:length]
                result = result.decode('gbk').encode('utf-8')
                logging.debug("Got the child text is :" + result)
                last_child = child_control
                label_text = result
            time.sleep(0.5)

        def _winfun(hwnd, lparam):
            s = win32gui.GetWindowText(hwnd)
            s = s.decode('gbk').encode('utf-8')
            logging.debug("winfun, child_hwnd: %d   txt: %s" % (hwnd, s))
            return 1

        if window:
            logging.debug("To enumerate all the child windows")
            win32gui.EnumChildWindows(self.expect_sec_window, _winfun, None)

        #bufferlength = struct.pack('i', 255)
        #count = win32gui.SendMessage(self.expect_sec_window, win32con.get, 0, 0)
        #for itemIndex in range(count):
        #    value = array.array('c', bufferlength +str().ljust(253))
        #    valueLength = win32gui.SendMessage(self.expect_sec_window, getValueMessage, itemIndex, value)
        #    yield value.tostring()[:valueLength]



        return label_text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号