win32gui MoveWindow() 未与屏幕左边缘对齐 [英] win32gui MoveWindow() not aligned with left edge of screen

查看:193
本文介绍了win32gui MoveWindow() 未与屏幕左边缘对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用win32gui将一个记事本窗口移动到屏幕原点(0, 0),宽高为500,结果是窗口没有移动到真正的左边框但 ~10 像素.向右.宽度和高度也不等于 500 像素.(~620 像素.代替).
我正在使用以下代码来生成结果.

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:

这里是 img 的图片:

推荐答案

Windows 10 有一个 7 像素的不可见边框.(如果包含可见的 1 像素窗口边框,则总计为 8 像素.)它是用于调整窗口大小的边框,位于窗口的左侧、右侧和底部边缘.

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.

一个简单的解决方法是在 MoveWindow 中偏移 x.

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)

这篇关于win32gui MoveWindow() 未与屏幕左边缘对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆