windows 10 screen coordinates are offset by 7

前端 未结 2 1073
天涯浪人
天涯浪人 2020-12-09 23:35

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 c

相关标签:
2条回答
  • 2020-12-10 00:12

    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.

    0 讨论(0)
  • 2020-12-10 00:22

    This is because of the width of the window border and other factors, which vary depending on OS version, user preference, and DPI settings. See the GetSystemMetrics function.

    0 讨论(0)
提交回复
热议问题