On Windows 11 GetWindowRgn doesn't seem to return the rounder corners region, just gives an ERROR.

Robin Krom 11 Reputation points
2022-04-25T15:29:28.663+00:00

Hello,

I am the maintainer of Greenshot, a free & open source Windows screenshot application. (Found here: https://getgreenshot.org)

With Windows 11 there are now windows with rounded edges, similar to Windows 7.
I want to make it possible for Greenshot to capture a screenshot of the window without having pixels on it which do not belong to the window.

I was hoping to that I can use GetWindowRgn, like with Windows 7, which would return a Region specifying this, as described here:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrgn

But for Windows 11 this doesn't work, it just returns ERROR, like there is no region.

Is this a shortcoming in Windows 11, or is there another way to see where the corners are?
I know already of DWMWA_WINDOW_CORNER_PREFERENCE as specified here: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
but this doesn't help me with getting the corner information itself.

Any tips or ideas here?

Best wishes,
Robin

Windows development | Windows API - Win32
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Robin Krom 11 Reputation points
    2022-04-26T06:52:43.98+00:00

    Hello,

    Thank you for the quick answer!! That was really speedy!

    For Windows 10 an ERROR result makes sense, there are no rounded corners so windows are always a rectangle and thus do not need a region.
    No rounded corners made it easy on Windows 10 to create professional screenshots, but on Windows 11 a rectangle capture of a window with rounded corners where the parts (pixels) behind it are visible, is not what our users like.

    This is why I took Windows 7 as an example for the region, all windows versions after that only had rectangle windows and thus no regions.
    For backwards compatibility, this makes sense to compare, in Windows 7 there were regions when the window had corners.
    Maybe you can ask around why this was removed?

    I'll have a look at the example, but it's in cpp and I am a C# developer, and my Visual Studio complains about it being for VS 2017... Although I already looked at: https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/screen-capture and there was a weird UI, which breaks user experience. But I will check it out.

    I also found that PrintWindow, with the undocumented flag "PW_RENDERFULLCONTENT" (value 2). gets me a screenshot of a window without corners (it looks like a Windows 10 window), see here: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-printwindow
    But somehow it has issues where there are black pixels left of the capture, I was thinking about creating a different issue for that.

    I'm actually tracking my current experience here: https://github.com/greenshot/greenshot/issues/373

    Best wishes,
    Robin

    1 person found this answer helpful.

  2. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2022-04-26T05:50:18.95+00:00

    Hello,

    Welcome to Microsoft Q&A!

    After testing, GetWindowRgn returns ERROR on Windows10 & Windows11. That could mean The specified window does not have a region.
    You can refer to ScreenCaptureforHWND which can capture the rounder corners frame. But It seems the Window is rectangle even through It‘s corner rounded.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.