def captureAlbumArt(self):
while(self.windowHandle != GetForegroundWindow()):
SetForegroundWindow(self.windowHandle)
time.sleep(WAIT_TIME) ## Give Spotify a moment to come to the foreground
ShowWindow(self.windowHandle, SW_SHOWMAXIMIZED)
time.sleep(WAIT_TIME) ## Give Spotify a second to become maximized
## Get the edges of the window
left, top, right, bottom = GetWindowRect(self.windowHandle)
left += self.artOffsets[0]
bottom -= self.artOffsets[1]
## Get the album art's location from those edges and user specified offsets.
region = (left, bottom - self.artSideLength, left + self.artSideLength, bottom)
return pyscreenshot.grab(bbox=region, childprocess=False)
python类GetWindowRect()的实例源码
def hwd_get_pos(list,tuple):
for x in list:
if isinstance(x,(int)):
print 'hwd:', x,' pos: ', win32gui.GetWindowRect(x)
if win32gui.GetWindowRect(x) ==tuple:
return x
return 0
def dumpWindow_pos(hwnd):
'''Dump all controls from a window into a nested list
Useful during development, allowing to you discover the structure of the
contents of a window, showing the text and class of all contained controls.
Arguments: The window handle of the top level window to dump.
Returns A nested list of controls. Each entry consists of the
control's hwnd, its text, its class, and its sub-controls,
if any.
Usage example: replaceDialog = findTopWindow(wantedText='Replace')
pprint.pprint(dumpWindow(replaceDialog))
'''
windows = []
try:
win32gui.EnumChildWindows(hwnd, _windowEnumerationHandler, windows)
except win32gui.error:
# No child windows
return
windows = [list(window) for window in windows]
for window in windows:
childHwnd, windowText, windowClass = window
window_content = dumpWindow(childHwnd)
if window_content:
window.append(window_content)
print '###################'
print childHwnd,'pos:',win32gui.GetWindowRect(childHwnd),'window_content:',window_content
tuple_t = win32gui.GetWindowRect(childHwnd)
if tuple_t[0]==179 and tuple_t[2]==561:
print window_content[0][0],'pos:',win32gui.GetWindowRect(window_content[0][0])
if window_content[0][0]:
bufLen=1024
buf =win32gui.PyMakeBuffer(bufLen)
n = win32gui.SendMessage(window_content[0][0],win32con.WM_GETTEXT,bufLen,buf)
str = buf[:n]
print str
print getEditText(window_content[0][0])
time.sleep(1)
#win32gui.SendMessage(window_content[0][0],win32con.WM_SETTEXT,None,'Realtek 10/100/1000 Ethernet NIC')
print '###################'
return windows
def FX_GetWindowRect(Win32Window):
return win32gui.GetWindowRect(Win32Window)
def create_boundingbox(self, hwnd = None, windows_style=False):
"""
Creates a bounding box of the window.
Args:
hwnd (int): the window handle we are going to find. If not supplied
the hwnd from the last get_hwnd_by_title will be used
Returns:
Creates a tuple with four elements. The upper left coordinates
and the lower right coordinates. (left, top, right,buttom window borders)
"""
if hwnd is None:
hwnd = self.get_hwnd()
logging.debug('Trying to find the box for 0x{:2X}'.format(hwnd))
self.bbox = win32gui.GetWindowRect(hwnd)
logging.debug('Found {}'.format(self.bbox))
if windows_style:
pos_size = self.get_bbox_size(self.get_bbox())
return ()
else:
return self.bbox