win32

根据名称查找窗口

# -*- coding: utf-8 -*-
import win32gui
import re

def getWindowFullName(halfName):

    hWndList = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)

    halfName = u'.*' + halfName + u'.*'
    pattern = re.compile(halfName,re.S)

    for hWnd in hWndList:
        result = re.search(pattern,win32gui.GetWindowText(hWnd))
        if result:
            return result.group(0)
    return None

if __name__ == '__main__':
    print(getWindowFullName(u'另存为'))

获取所有窗口

# -*- coding: utf-8 -*-
import win32gui
import re

def getWindowFullName(halfName):

    hWndList = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)

    for hWnd in hWndList:
        hWndWindowText = win32gui.GetWindowText(hWnd)
        if hWndWindowText:
            print(hWnd, hWndWindowText)

if __name__ == '__main__':
    print(getWindowFullName(u''))