简体   繁体   English

python win32com.client调整大小窗口

[英]python win32com.client resize window

I am using Python 3.4.1 to control a Windows Application through win32com.client. 我正在使用Python 3.4.1通过win32com.client控制Windows应用程序。 I can activate it,I can send keystrokes, click, etc. Now I am wondering if there is a way to resize the window and set it to a specific position. 我可以激活它,可以发送击键,单击等。现在我想知道是否有一种方法可以调整窗口的大小并将其设置到特定位置。 I can't find a method for that. 我找不到解决方法。 here some code snippets, so you know what I am talking about 这里有一些代码片段,所以您知道我在说什么

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
???

I was trying to solve a similar task, and found that win32gui from pywin32 package does the job. 我试图解决类似的任务,发现pywin32包中的win32gui可以完成这项工作。

Here's a small example: 这是一个小例子:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM