D
D
Danneborg2018-06-08 07:21:58
Python
Danneborg, 2018-06-08 07:21:58

How to maximize any window from currently running programs in python?

I wanted to create a bot whose tasks it will take screenshots of the window, analyze them and, based on the results of the analysis, issue commands to the window. I can’t solve the question of how I can switch between windows in windows. , screen, analyzed, gave a command, opened the next window, and so on in a circle. For this, apparently, you need to use win32gui, but unfortunately I did not find a clear example (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TomasHuk, 2018-06-08
@TomasHuk

It, no?
https://stackoverflow.com/questions/2090464/python...
I once wrote for myself, returns a list with the title of all windows, maybe try this:

import ctypes

EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible

titles = []

def foreach_window(hwnd, lParam):
    if IsWindowVisible(hwnd):
        length = GetWindowTextLength(hwnd)
        buff = ctypes.create_unicode_buffer(length + 1)
        GetWindowText(hwnd, buff, length + 1)
        titles.append(buff.value)
    return True

EnumWindows(EnumWindowsProc(foreach_window), 0)

def main():
    print(titles)
    for t in titles:
        print(t)
    return titles

if __name__ == '__main__':
    main()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question