파이썬에서 다른 실행 프로세스 창 크기를 얻으십시오
문제
이것은 소리만큼 악의적이지 않습니다. 나는 창의 현재 크기를 얻고 싶습니다. 목적은 다른 모든 창문이 전체 화면이라면 그렇게 시작해야한다는 것을 알아내는 것입니다. 또는 다른 모든 프로세스가 큰 해결책이 있음에도 불구하고 다른 모든 프로세스가 800x600에 불과하다면 아마도 사용자가 원하는 것일 것입니다. 왜 그들이 시간을 낭비하고 에너지를 낭비하게 만드는 이유는 내 창을 다른 사람들과 일치시키기 위해 내 창을 크게 조정합니까? 나는 주로 Windows Devoloper이지만이를 수행 할 크로스 플랫폼 방법이 있다면 최소한 화를 내지 않을 것입니다.
해결책
힌트를 사용합니다 Windowmover 기사 그리고 Nattee Niparnan의 블로그 게시물 나는 이것을 만들었다 :
import win32con
import win32gui
def isRealWindow(hWnd):
'''Return True iff given window is a real Windows application window.'''
if not win32gui.IsWindowVisible(hWnd):
return False
if win32gui.GetParent(hWnd) != 0:
return False
hasNoOwner = win32gui.GetWindow(hWnd, win32con.GW_OWNER) == 0
lExStyle = win32gui.GetWindowLong(hWnd, win32con.GWL_EXSTYLE)
if (((lExStyle & win32con.WS_EX_TOOLWINDOW) == 0 and hasNoOwner)
or ((lExStyle & win32con.WS_EX_APPWINDOW != 0) and not hasNoOwner)):
if win32gui.GetWindowText(hWnd):
return True
return False
def getWindowSizes():
'''
Return a list of tuples (handler, (width, height)) for each real window.
'''
def callback(hWnd, windows):
if not isRealWindow(hWnd):
return
rect = win32gui.GetWindowRect(hWnd)
windows.append((hWnd, (rect[2] - rect[0], rect[3] - rect[1])))
windows = []
win32gui.EnumWindows(callback, windows)
return windows
for win in getWindowSizes():
print win
당신은 필요합니다 Python 모듈의 Win32 확장 이것이 작동하기 위해.
편집 : 나는 그것을 발견했다 GetWindowRect
보다 더 정확한 결과를 제공합니다 GetClientRect
. 소스가 업데이트되었습니다.
다른 팁
나는 큰 팬입니다 오토이트. Python에서 대부분의 기능을 사용할 수있는 COM 버전이 있습니다.
import win32com.client
oAutoItX = win32com.client.Dispatch( "AutoItX3.Control" )
oAutoItX.Opt("WinTitleMatchMode", 2) #Match text anywhere in a window title
width = oAutoItX.WinGetClientSizeWidth("Firefox")
height = oAutoItX.WinGetClientSizeHeight("Firefox")
print width, height
확인하십시오 win32gui
기준 치수 Python의 Windows Extensions에서. 원하는 기능을 제공 할 수 있습니다.
제휴하지 않습니다 StackOverflow