I am using win32gui
to move a Notepad window to the origin of the screen (0, 0) with width and height equal to 500. The result is that the window is not moved to the true left border but ~10 px. to the right. Also the width and height do not equal 500 px. (~620 px. instead).
I am using the following code to produce my results.
import win32gui
from PIL import ImageGrab
# Open notepad.exe manually.
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
win32gui.MoveWindow(hwnd, 0, 0, 500, 500, True)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
Here a screenshot of the overall position of the window on the screen:
And here a picture of img
:
Windows 10 has an invisible border of 7 pixels. (Totaling to 8 pixels if you include the visible 1 pixel window border.) It is the border for resizing windows which is on the left, right and bottom edge of the window.
Notice how the resizing cursor reacts with the top edge. There is no invisible border there.
An easy fix is to just offset the x
in MoveWindow
.
win32gui.MoveWindow(hwnd, -7, 0, 500, 500, True)
Or make a new function to do that:
def move_window(hwnd, x, y, n_width, n_height, b_repaint):
win32gui.MoveWindow(hwnd, x - 7, y, n_width, n_height, b_repaint)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With