Windows 11, PerMonitorV2 is NOT automatically scaling non-client areas of my window.

Robinson 146 Reputation points
2023-05-15T08:24:55.89+00:00

I have a manifest containing:

<asmv3:windowsSettings xmlns='http://schemas.microsoft.com/SMI/2005/WindowsSettings'>
	<dpiAware>True/PM</dpiAware>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns='https://schemas.microsoft.com/SMI/2016/WindowsSettings'>
	<dpiAwareness>PerMonitorV2,PerMonitor</dpiAwareness>
</asmv3:windowsSettings>

I am asserting this is the case in my _tWinMain function:

#ifdef _DEBUG
	{
		auto context = GetThreadDpiAwarenessContext();
		auto awareness = GetAwarenessFromDpiAwarenessContext(context);

		assert(awareness == DPI_AWARENESS::DPI_AWARENESS_PER_MONITOR_AWARE);
	}

#endif // _DEBUG

GetWindowDpiAwarenessContext also returns DPI_AWARENESS_PER_MONITOR_AWARE. I'm wondering why it doesn't return DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, and why DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 isn't in the enum defined in WinDef.h. I'm using platform SDK version 10.0.22621.0, Visual Studio 2022 17.5.5.

The documentation claims this setting automatically scales non-client areas of my window. However it does not. On my 4K monitor the non-client areas are tiny. The rest of the application correctly calculates the scale factor for the components I scale myself however.

I have checked the .exe properties in Explorer to make sure there's no behaviour override going on. Both boxes on its high DPI settings are unchecked.

What mistake have I made? Or does this stuff just not work correctly out of the box?

EDIT: If I call EnableNonClientDpiScaling in WM_NCCREATE, I get the correct non-client area scaling. This is a hint that my process, thread or window isn't DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2. It must just be as it said, DPI_AWARENESS_PER_MONITOR_AWARE. So the question then, is why, when I specified _V2 in the manifest.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,648 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,754 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2023-05-16T01:25:58.1966667+00:00

    Older APIs offer less functionality. Have you checked your process DPI Awareness in Task Manager? Have you tried to set default awareness programmatically with recommended SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)?

    1 person found this answer helpful.

  2. Robinson 146 Reputation points
    2024-07-20T14:09:28.17+00:00

    I've come here with the actual answer in case someone else has this problem. If you look carefully at my manifest xlm from the original post you'll see a little mistake. The url should be http not https. This is apparently very important!

    <asmv3:windowsSettings xmlns='http://schemas.microsoft.com/SMI/2016/WindowsSettings'>
    
    1 person found this answer helpful.

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.