使用多个台式机时在监视器之间移动窗口

发布于 2025-01-28 16:48:56 字数 585 浏览 2 评论 0原文

下面的脚本将窗口从我的左监视器移动到右侧显示器(每个2560x1440),

win = win32gui.GetForegroundWindow()
winPlacement = list(win32gui.GetWindowPlacement(win))

left, top, right, bottom = winPlacement[4]
winPlacement[4] = (left + 2560, top, right + 2560, bottom)
  
win32gui.SetWindowPlacement(win, winPlacement)

乍一看,该功能正常工作 - 窗口可移动到同一位置,但在正确的监视器上。只要我在同一台式机上,它就会处于这个位置。

但是,当我切换到另一个桌面(Ctrl + Win +→)并返回(Ctrl + Win +←)时,窗口又回到了原始位置。我尝试使用函数moveWindow,但行为相同。当窗口与同一监视器的边界移动时,此问题不存在。

似乎Windows将这个旧位置存储在某个地方,并每次切换到另一个桌面时都将其涂抹回。这是一个错误,还是我必须做其他事情来制造这个新的位置固定?

The following script moves window from my left monitor to the right monitor (2560x1440 each)

win = win32gui.GetForegroundWindow()
winPlacement = list(win32gui.GetWindowPlacement(win))

left, top, right, bottom = winPlacement[4]
winPlacement[4] = (left + 2560, top, right + 2560, bottom)
  
win32gui.SetWindowPlacement(win, winPlacement)

At first glance, the function is working fine - window is moved to the same spot but on the right monitor. It stays in this position as long as I am on the same desktop.

But when I switch to another desktop (CTRL + WIN + →) and return back (CTRL + WIN + ←) the window is back on it's original position. I tried to use function MoveWindow but it behaves the same. This problem is not present when the window is moved withing the bounds of the same monitor.

It seems like windows is storing this old position somewhere and applying it back every time I switch to another desktop. Is this a bug or do I have to do something else to make this new position permament?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文