Created
June 8, 2012 10:35
-
-
Save t2psyto/2894935 to your computer and use it in GitHub Desktop.
change Chrome window title text by python win32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import ctypes | |
| user32 = ctypes.windll.user32 | |
| def getClassName(hwnd): | |
| resultString = ctypes.create_string_buffer("\000" * 32) | |
| user32.GetClassNameA(hwnd, resultString, len(resultString)) | |
| return resultString.value | |
| def text(hwnd): | |
| length = user32.GetWindowTextLengthA(hwnd) | |
| if length: | |
| buffer = ctypes.create_string_buffer("",length + 1) | |
| if user32.GetWindowTextA(hwnd, buffer, length +1): | |
| return buffer.value | |
| def proc(hwnd, user): | |
| if write_file == True: | |
| value = hwnd, text(hwnd), getClassName(hwnd) | |
| fo.write(str(value) + "?n") | |
| else: | |
| #if getClassName(hwnd) == "Chrome_WidgetWin_1": #search by WindowsClass name | |
| if text(hwnd) != None and text(hwnd)[-8:] == "- Chrome": #search by titlebar text | |
| print hwnd, type(text(hwnd)), text(hwnd), getClassName(hwnd) | |
| user32.SetWindowTextA(hwnd,ctypes.c_char_p("hoeg")) #change titlebar text | |
| return 1 | |
| def run(): | |
| WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_long) | |
| user32.EnumWindows(WNDENUMPROC(proc), 0) | |
| return 1 | |
| if __name__ == '__main__': | |
| if len(sys.argv) == 2: | |
| write_file = True | |
| fo = file(sys.argv[1]+".txt", "w") | |
| run() | |
| fo.close() | |
| else: | |
| write_file = False | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment