gpt4 book ai didi

python win32com.client 调整窗口大小

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:18 26 4
gpt4 key购买 nike

我正在使用 Python 3.4.1 通过 win32com.client 控制 Windows 应用程序。我可以激活它,我可以发送击键、点击等。现在我想知道是否有办法调整窗口大小并将其设置到特定位置。我找不到方法。这里有一些代码片段,所以你知道我在说什么

import win32api, win32con, time, win32com.client, random, sys, winsound, datetime

...


def click_mouse(x,y, p_wait=0.1):
win32api.SetCursorPos((x,y))
time.sleep(p_wait)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

def move_mouse(x,y):
win32api.SetCursorPos((x,y))
time.sleep(0.5)

def activate():
global shell
shell=win32com.client.Dispatch("Wscript.Shell")
success = shell.AppActivate("App")

def resize():
global shell
???

最佳答案

我试图解决类似的任务,发现 pywin32 包中的 win32gui 可以完成这项工作。

这是一个小例子:

import win32gui
hwnd = win32gui.FindWindow(None, 'Window Title')
x0, y0, x1, y1 = win32gui.GetWindowRect(hwnd)
w = x1 - x0
h = y1 - y0
win32gui.MoveWindow(hwnd, x0, y0, w+100, h+100, True)

关于python win32com.client 调整窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26616191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com