赞
踩
pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
import win32gui
# 获取窗口句柄
hwnd = win32gui.FindWindow(None, '命令提示符')
# 获取窗口文本内容
text = win32gui.GetWindowText(hwnd)
print(text)
# 获取窗口的类名
className = win32gui.GetClassName(hwnd)
print(className)
# 获取窗口的位置和大小
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
width = right - left
height = bottom - top
print('left: %s, top: %s, width: %s, height: %s' % (left, top, width, height))
========================
import win32gui
# 查找窗口句柄
def getHwnd(clzName,title):
hwnd = win32gui.FindWindow(clzName, title)
return hwnd
# 获取窗口标题
def getTitle(hwnd):
return win32gui.GetWindowText(hwnd)
# 查找控件句柄
def getChildHwnd(hwnd,parentHwnd,clzName,winName):
return win32gui.FindWindowEx(hwnd, parentHwnd, clzName, winName)
# 窗口位置大小
def get_window_pos_size(hwnd):
window_rect = win32gui.GetWindowRect(hwnd)
x = window_rect[0]
y = window_rect[1]
width = window_rect[2] - x
height = window_rect[3] - y
return x, y, width, height
最小化窗口:win32gui.MinimizeWindow(handle)
最大化窗口:win32gui.MaximizeWindow(handle)
还原窗口:win32gui.RestoreWindow(handle)
激活窗口:win32gui.SetActiveWindow(handle)
置顶窗口:win32gui.SetForegroundWindow(handle)
取消置顶:win32gui.SetForegroundWindow(0)
设置窗口大小:win32gui.SetWindowPos(handle, None, x, y, width, height, flags)
获取窗口大小:win32gui.GetWindowRect(handle)
移动窗口:win32gui.MoveWindow(handle, x, y, width, height, repaint)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。