# -*- coding:cp949 -*- # TeraCopy 내부의 모든 윈도우 객체를 나열합니다. import win32gui import win32con import commctrl import pywintypes import struct, array import sys from ListViewItems import GetListViewItems # 부모 윈도우의 핸들을 검사합니다. class WindowFinder: def __init__(self, windowname): try: win32gui.EnumWindows(self.__EnumWindowsHandler, windowname) except pywintypes.error as e: # 발생된 예외 중 e[0]가 0이면 callback이 멈춘 정상 케이스 if e[0] == 0: pass def __EnumWindowsHandler(self, hwnd, extra): wintext = win32gui.GetWindowText(hwnd) if wintext.find(extra) != -1: self.__hwnd = hwnd return pywintypes.FALSE # FALSE는 예외를 발생시킵니다. def GetHwnd(self): return self.__hwnd __hwnd = 0 # 자식 윈도우의 핸들 리스트를 검사합니다. class ChildWindowFinder: def __init__(self, parentwnd): try: win32gui.EnumChildWindows(parentwnd, self.__EnumChildWindowsHandler, None) except pywintypes.error as e: if e[0] == 0: pass def __EnumChildWindowsHandler(self, hwnd, extra): self.__childwnds.append(hwnd) def GetChildrenList(self): return self.__childwnds __childwnds = [] # teracopy의 보고 기능 class teracopy_reporter: def __init__(self, windowname): self.__GetChildWindows(windowname) # windowname을 가진 윈도우의 모든 자식 윈도우 리스트를 얻어낸다. def __GetChildWindows(self, windowname): # TeraCopy의 window handle을 검사한다. self.__hwnd = WindowFinder(windowname).GetHwnd() # Teracopy의 모든 child window handle을 검색한다. self.__childwnds = ChildWindowFinder(self.__hwnd).GetChildrenList() # 리스트 뷰 컨트롤의 텍스트를 파일로 저장합니다. def report_status(self, save_as): listviewCtrl = 0 for child in self.__childwnds: wnd_clas = win32gui.GetClassName(child) if wnd_clas == 'SysListView32': listviewCtrl = child break item_grid = [] for i in range(5): column = GetListViewItems(listviewCtrl, i) item_grid.append(column) # html로 쓰기 html = '' with open(save_as, 'w') as f: html += "\n" html += "\n\t\n\t\t\n" html += "\t\tTeraCopy Status\n\t\n" html += "\n" # 폼 요소가 추가되었습니다. ######################################################## html += "\t
\n" html += "\t\t
\n" html += "\t\t\t\n\n" html += "\t\t\t\n" html += "\t\t
\n" html += "\t
\n" ################################################################################# html += "\t\n" html += "\t\t\n" html += "\t\t\t\n" html += "\t\t\t\n" html += "\t\t\t\n" html += "\t\t\t\n" html += "\t\t\t\n" html += "\t\t\n" for r in range(len(item_grid[0])): html += "\t\t\n" html += "\t\t\t\n" \ "\t\t\t\n" \ "\t\t\t\n" \ "\t\t\t\n" \ "\t\t\t\n" % \ (item_grid[0][r], item_grid[1][r], item_grid[2][r], item_grid[3][r], item_grid[4][r]) html += "\t\t\n" html += "\t
원본파일크기상태원본 CRC대상 CRC
%s%s%s%s%s
\n" html += "\n\n" f.write(html) def toggle_listview(self): btnwnd = 0 for child in self.__childwnds: wnd_clas = win32gui.GetClassName(child) wnd_text = win32gui.GetWindowText(child) if wnd_clas == 'Button' and (wnd_text == '더 보기' or wnd_text == '간단하게'): btnwnd = child break win32gui.SendMessage(btnwnd, win32con.WM_LBUTTONDOWN, 0x01, 0xF0035) win32gui.SendMessage(btnwnd, win32con.WM_LBUTTONUP, 0x00, 0xF0035) __hwnd = 0 __childwnds = 0 if __name__ == '__main__': tr = teracopy_reporter('TeraCopy') tr.toggle_listview()