Skip to content

Instantly share code, notes, and snippets.

@ethanhs
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanhs/d80c66b2d5826a46589e to your computer and use it in GitHub Desktop.
Save ethanhs/d80c66b2d5826a46589e to your computer and use it in GitHub Desktop.
import ctypes
from ctypes import wintypes
#imports
GetWindowLong=ctypes.windll.user32.GetWindowLongW
SetWindowLong=ctypes.windll.user32.SetWindowLongW
SetLayeredWindowAttributes=ctypes.windll.user32.SetLayeredWindowAttributes
GetShell=ctypes.windll.user32.GetShellWindow
EnumChildren = ctypes.windll.user32.EnumChildWindows
EnumWindows=ctypes.windll.user32.EnumWindows
GetWindowText = ctypes.windll.user32.GetWindowTextW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
GetClassName=ctypes.windll.user32.GetClassNameW
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int))
#handy class for all my functions
class Main:
def __init__(self):
self.all=[]
self.allnames=[]
self.titles=[]
shell=GetShell()
self.EnumWindows = ctypes.windll.user32.EnumWindows
self.EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int))
self.titles = []
self.all = []
self.allnames = []
def GetHandles(self):
self.EnumWindows(self.EnumWindowsProc(self.GetHWND), 0)
for item in self.titles:
EnumChildren(item, self.EnumWindowsProc(self.GetHWND), 0)
self.EnumWindows(self.EnumWindowsProc(self.GetHWND), 0)
return self.titles
def GetHWND(self, hwnd, lParam):
if IsWindowVisible(hwnd):
length = GetWindowTextLength(hwnd)
buff = ctypes.create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
self.titles.append(hwnd)
return True
def classname(self,handle):
class_name = (ctypes.c_wchar * 257)()
GetClassName(handle, ctypes.byref(class_name), 256)
return class_name.value
if __name__=="__main__":
m=Main()
hwnds= m.GetHandles()
for h in hwnds:
if m.classname(h)==u"WorkerW":
SetWindowLong(h, -20, GetWindowLong(h, -20))
SetLayeredWindowAttributes(h,0,0,0x00000002)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment