How to catch printer event in python

To be notified of new print jobs, you can use FindFirstPrinterChangeNotification, FindNextPrinterChangeNotification, and a wait function from kernel32 such as WaitForSingleObject. Here’s an example to set a filter that waits for a new print job on the local print server. There’s much more work to be done if you want the JOB_NOTIFY_FIELD_DOCUMENT value out of … Read more

Screenshot of inactive window PrintWindow + win32gui

After lots of searching and trying various different methods, the following worked for me. import win32gui import win32ui from ctypes import windll import Image hwnd = win32gui.FindWindow(None, ‘Calculator’) # Change the line below depending on whether you want the whole window # or just the client area. #left, top, right, bot = win32gui.GetClientRect(hwnd) left, top, … Read more

Write image to Windows clipboard in python with PIL and win32clipboard?

from cStringIO import StringIO import win32clipboard from PIL import Image def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() filepath=”image.jpg” image = Image.open(filepath) output = StringIO() image.convert(“RGB”).save(output, “BMP”) data = output.getvalue()[14:] output.close() send_to_clipboard(win32clipboard.CF_DIB, data)

Get other running processes window sizes in Python

Using hints from WindowMover article and Nattee Niparnan’s blog post I managed to create this: 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 … Read more

GetWindowRect too small on Windows 7

My first thoughts were listed below but if, as you state, you’re certain that GetWindowRect is returning incorrect values, see RESOLUTION further down. “What’s wrong with GetSystemMetrics(SM_CXBORDER) and GetSystemMetrics(SM_CYBORDER)? The method you’re using seems a very roundabout way of doing it and, if you can call GetWindowRect(), I’m pretty certain you can call GetSystemMetrics() as … Read more