zoukankan      html  css  js  c++  java
  • get hwnd of each window with python

    coding:utf-8

    print each window

    import win32gui
    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

    name = '姚峰杰'.decode('utf-8')
    hwnd = win32gui.FindWindow(0, name)

    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(hwnd) # , buff.value
    return True
    EnumWindows(EnumWindowsProc(foreach_window), 0)

    for i in range(len(titles)):
    print titles[i]

    ctypes.windll.user32.MoveWindow(titles[5][0], 0, 0, 760, 500, True)

    ctypes.windll.user32.SwitchToThisWindow(hwnd, True)

  • 相关阅读:
    linux笔记
    ui转化为py
    stl学习
    React第一课
    React 第一课
    创建一个类
    nodejs基本语法
    let和const
    qml_status笔记
    controller层的单元测试
  • 原文地址:https://www.cnblogs.com/otfsenter/p/6548029.html
Copyright © 2011-2022 走看看