WindowFinder.py 文件源码

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

项目:myautotest 作者: auuppp 项目源码 文件源码
def _window_enum_dialog_callback_(self, hwnd, extra):
        '''Call back func which checks each open window and matches the name of window using reg ex'''
        #self._handle = None
        matchtext = extra 
        logging.debug("call _window_enum_dialog_callback")
        classname = win32gui.GetClassName(hwnd)
        title_text = win32gui.GetWindowText(hwnd)
        title_text = title_text.decode('gbk').encode('utf-8')
        if classname == '#32770':
            matchtext = matchtext.encode('utf-8')
            logging.debug("msg: " + matchtext)
            logging.debug("Title is: " + title_text)
#             buf_size = 1 + win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0)
#             buffer_text = win32gui.PyMakeBuffer(buf_size)
#             win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buf_size, buffer_text)
#         
#             logging.debug("Buffer_text: " + buffer_text)
#             logging.debug("Buffer_text decode(gbk).encode(utf-8): " + 
#                           buffer_text.decode('gbk').encode('utf-8'))
#             windowText = buffer_text[:buf_size]
# 
#             try:
#                 windowText = windowText.decode('gbk').encode('utf-8') #unicode(windowText, 'utf-8')
#             except:
#                 logging.debug("_window_enum_dialog_callback unicode exception")
#                 pass
# 
#             message = ['Handle:\t' + str(hwnd),
#                    'Class Name:\t' + classname,
#                    'Window Text:\t' + windowText]
#     
#             logging.debug("Print the message: " + str(message))
#                
#             #if re.match(wildcard, windowText) != None:

            if (matchtext.strip() == title_text.strip()):
                logging.debug("!!!!BINGO!!!!")
                self.hwnd = hwnd
                return False
            else:
                logging.debug("No matched .....")
                return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号