SystemParametersInfoForDpi will corrupt the window title font on rescaling

Miroslav Pavlíček 10 Reputation points
2023-05-23T08:43:19.9733333+00:00

There is a simple console application, created from default Visual Studio template. At startup, the following code is added:

NONCLIENTMETRICSW ncInfo{};
ncInfo.cbSize = sizeof(ncInfo);
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(ncInfo), &ncInfo, 0, 72);

When this function is called, everything works correctly until the scale (%) in Windows display setting is changed. After that, the font of window title of all windows in the system becomes very tiny until restart or sign out/in. Without this function call, this issue does not exist and changes of display scale percentage do not damage the windows title font.

Here I send a gif video of the process of setting up the situation:

  • Create empty project.
  • Run it and after that try to change display scale - everything OK.
  • Add given 3 lines of code into project and run it.
  • After display scale change, windows title font is not correct now.
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,065 questions
{count} vote