Windows 10屏幕坐标偏移7 [英] windows 10 screen coordinates are offset by 7

查看:237
本文介绍了Windows 10屏幕坐标偏移7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 10上使用c ++进行编码-直接是win32 API。



我想在屏幕的右上方显示一个窗口。
在执行此操作时,我注意到最大化窗口的屏幕坐标为left = -8,top = -8,right = 1936,bottom = 1088。



此外,当我将窗口的位置设置为right = 1920且top = 0时,右侧大约有8个像素的间隙。我尝试过移动窗口以查看得到的屏幕坐标。



rect.left,未最大化的窗口可以从-7到1912年。



所以东西滑了7个像素? WTF微软??



我应该如何提出rec.right = 1913值来将窗口对齐到屏幕右侧而没有悬空间隙?



但是1920年的rect.right留下了空白。因此,1912年的rect.right会留下更多的空白...



我需要一种可以在Vista下使用的解决方案。
win10之前,该rect.right应该像您期望的那样为1920。



Whaaaaat正在进行吗?我要开始把刀扔了!



代码明智,这就是GetWindowRect正在报告的内容...
(请问我奇怪的调试功能)

  :: GetWindowRect(_wndo,r); 

DBG( ExtRc l =`dr =`dt =`db =`dw =`dh =`d,
r-> left,r-> right,r ->顶部,r->底部,r->右-r->左侧,r->底部-r->顶部);


解决方案

非常感谢@ChristopherOicles
这是真的是他的答案。将其复制为您自己的(或进行调整,无论如何),我会接受您的。



发生了什么事,微软破坏了Windows 10中的边框宽度。



GetWindowRect返回外部窗口坐标作为屏幕坐标。
GetClientRect返回窗口内部的坐标。
直到Windows 10(FU Win10 !!),



它们之间的宽度和高度差是边框的宽度和高度。



在win10上,边框宽度报告为16像素,因此侧面为8像素。
但是,这些像素中只有1个可见。其中7个是透明的。
因此,您的窗口在左侧,右侧和底部都有透明的7像素。



因此,如果您需要重新以编程方式将屏幕上的窗口对齐。用户不希望屏幕边框旁边有7个像素的间隙!屏幕坐标中的边框。与GetWindowRect相似,但是rect不包括不可见性。



大多数时候,您仍然需要GetWindowRect来设置宽度和高度。您的窗口和每侧7个像素的不可见性都需要通过编程来正确调整窗口的大小。



因此,请使用rect GetWindowRect返回的.left和DwmTerribleName返回的值的.left位置获得那7个像素的偏移量。



在我看来,在Microsoft这样做的人都应该立即被枪杀。
这是我不需要跳过的障碍。
这破坏了与过去的兼容性。


I'm coding in c++ on windows 10 - straight win32 API.

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.

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 for a nonmaximized window can go from -7 to 1912.

so things are slid by 7 pixels ? WTF microsoft ??

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 ?

But rect.right of 1920 leaves a gap. So rect.right of 1912 would leave MORE of a gap...

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 !!

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);

解决方案

Well thanks to @ChristopherOicles This is really his answer. Duplicate this as your own (or tweak it, whatever) and I'll accept your's.

What's going on is microsoft wrecking border widths in windows 10.

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.

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.

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 !

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.

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.

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.

这篇关于Windows 10屏幕坐标偏移7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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