简体   繁体   中英

python win32com.client resize window

I am using Python 3.4.1 to control a Windows Application through win32com.client. 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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