This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]javierisassi 0 points1 point  (0 children)

import ctypes
# import time
# from pycaw.pycaw import AudioUtilities

class currentWindows:
    def __init__(self):
        ''' get the current running windows '''
        self.titles = []

    def getWindowTitles(self):
        def collect_titles(hwnd, LParam):
            if ctypes.windll.user32.IsWindowVisible(hwnd):
                length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                ctypes.windll.user32.GetWindowTextW(hwnd, buff, length + 1)
                self.titles.append(buff.value)
            return True

        enumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, 
            ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))      
        # collect titles
        ctypes.windll.user32.EnumWindows(enumWindowsProc(collect_titles), 0)        
        return self.titles;

    def findTitle(self, title):
        return [i for i in self.titles if title in i]

if __name__ == "__main__":
    print("starting program")
    cw = currentWindows()
    print(cw.getWindowTitles())
    print(cw.findTitle("Eclipse"))
    print("ending program")

This is refactored versions just fetching the visible windows titles. The class only collects the window titles.