windows 10 屏幕坐标偏移 7
我在 windows 10 上用 c++ 编写代码 - 直接 win32 API.
I'm coding in c++ on windows 10 - straight win32 API.
我想在屏幕右上角显示一个窗口.在执行此操作时,我注意到最大化窗口的屏幕坐标为 left=-8、top=-8、right=1936、bottom=1088.
I wanted to make a window show up in the top right of the screen. As I was doing this, I noticed that screen coordinates for a maximized window are left=-8, top=-8, right=1936, bottom=1088.
此外,当我将窗口定位为 right=1920 且 top=0 时,右侧大约有 8 个像素的间隙.我试着四处移动窗口,看看我得到了什么屏幕坐标.
Also, when I position a window so right=1920 and top=0, there's about an 8 pixel gap on the right. I tried moving the window around to see what screen coordinates I got.
用于非最大化窗口的 rect.left 可以从 -7 到 1912.
rect.left for a nonmaximized window can go from -7 to 1912.
所以东西滑动了 7 个像素?WTF 微软??
so things are slid by 7 pixels ? WTF microsoft ??
我应该如何想出 rec.right=1913 值来定位我的窗口与屏幕右侧对齐而没有那个间隙?
How am I supposed to come up with the rec.right=1913 value to position my window aligned to right side of screen without that dang gap ?
但是 1920 年的 rect.right 留下了一个空白.所以 1912 年的 rect.right 会留下更多的差距......
But rect.right of 1920 leaves a gap. So rect.right of 1912 would leave MORE of a gap...
而且我需要一个可以恢复到 Vista 的解决方案.在 win10 之前,那个 rect.right 应该是 1920,就像你期望的那样.
And I need a solution that'll work back to Vista. Pre win10, that rect.right should be 1920 like ya expect.
这里发生了什么?我要开始扔刀了!!
Whaaaaat is going on here? I'm about to start throwing knives around !!
代码方面,这正是 GetWindowRect 报告的内容......(请原谅我奇怪的调试功能)
Code wise, this is just what GetWindowRect is reporting... (excuse my weird debugging function)
::GetWindowRect (_wndo, r);
DBG("ExtRc l=`d r=`d t=`d b=`d w=`d h=`d",
r->left, r->right, r->top, r->bottom, r->right-r->left, r->bottom-r->top);
推荐答案
感谢@ChristopherOicles这真的是他的答案.将其复制为您自己的(或对其进行调整),我会接受您的.
Well thanks to @ChristopherOicles This is really his answer. Duplicate this as your own (or tweak it, whatever) and I'll accept your's.
微软正在破坏 Windows 10 中的边框宽度.
What's going on is microsoft wrecking border widths in windows 10.
GetWindowRect 将外部窗口坐标作为屏幕坐标返回.GetClientRect 返回窗口内的坐标.直到 Windows 10(F U Win10 !!),
GetWindowRect returns the outside window coordinates as screen coordinates. GetClientRect returns the inside the window coordinates. Up until Windows 10 (F U Win10 !!),
它们之间的宽高差就是边框的宽高.
The difference in width and height between them was the width and height of the borders.
在 win10 上,边框宽度报告为 16 像素,因此每边为 8 像素.但是,这些像素中只有 1 个是可见的.其中7个是透明的.所以你的窗口在左边、右边和底部都有一个透明的 7 像素.
Upon win10, the border width reports 16 pixels, so 8 pixels a side. However, only 1 of those pixels are visible. 7 of them are transparent. So your window has a transparent 7 pixels to the left, right, and bottom.
因此,如果您要以编程方式在屏幕上排列窗口,则需要考虑这些透明的 7 个像素.用户不希望屏幕边框旁边有 7 个像素的间隙!
So you need to take those transparent 7 pixels into account if you're going to line up the window on the screen programmatically. The user doesn't want that 7 pixel gap next to the screen border !
具有属性 DWMWA_EXTENDED_FRAME_BOUNDS 的 DwmGetWindowAttribute 将获得屏幕坐标中实际显示的边框部分的宽度和高度.与 GetWindowRect 非常相似,但 rect 不包含不可见性.
DwmGetWindowAttribute with the attribute DWMWA_EXTENDED_FRAME_BOUNDS will get you the width and height of the ACTUALLY SHOWING part of the border in screen coordinates. So similar to GetWindowRect, but the rect does not include the invisible-ness.
在大多数情况下,您仍然需要 GetWindowRect 来设置窗口的宽度和高度,并且需要每边不可见的 7 个像素以编程方式正确调整窗口大小.
You're still going to need GetWindowRect most of the time to set the width and height of your window and those 7 pixels per side of invisible-ness are needed to size the window properly programmatically.
所以使用 rect GetWindowRect 返回的 .left 和 DwmTerribleName 返回的 .left 之间的差异来获得 7 个像素的偏移量.
So use the difference between the .left of the rect GetWindowRect returns and .left of what DwmTerribleName returns to get that 7 pixels of offset.
在我看来,在微软做这件事的人应该立即被枪决.这是一个我不需要跳过的箍.这破坏了与过去的兼容性.
In my opinion, whoever did this at Microsoft should be immediately shot. This is a hoop I didn't need to jump through. This breaks compatibility with the past.
相关文章