2014-10-28 53 views
1

我使用Python 3.4.1通過win32com.client控制Windows應用程序。我可以激活它,我可以發送擊鍵,點擊等。 現在我想知道是否有一種方法來調整窗口大小並將其設置爲特定位置。我找不到這樣的方法。 這裏的一些代碼片段,讓你知道我在說什麼python win32com.client調整窗口

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

回答

0

我試圖解決一個類似的任務,並發現win32guipywin32包做這項工作。

這裏有一個小例子:

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)