- 1 year ago
WM_DPICHANGED reducing size of the window
When handling the WM_DPICHANGED
message in Windows, it's important to properly handle the DPI (dots per inch) changes to maintain the correct size and appearance of your application window. Here are a few points to consider:
Understand DPI awareness: Ensure that your application is DPI-aware and has the appropriate DPI awareness level set in its manifest. This allows your application to scale correctly when the DPI changes.
Handle
WM_DPICHANGED
message: When receiving theWM_DPICHANGED
message, you should update the window size and position based on the new DPI settings. This involves adjusting the width, height, and position of the window to maintain the visual proportions and prevent content from becoming too small or cropped.Use
AdjustWindowRectExForDpi
: To calculate the correct window size for the new DPI, you can use theAdjustWindowRectExForDpi
function. It takes into account the window style, client size, and DPI to calculate the required window rectangle.Update window styles: Depending on the DPI change, you may need to adjust other window styles and attributes, such as font sizes or layout, to ensure the content remains readable and visually appealing at different DPI settings.
Handle scaling of custom controls: If your application contains custom controls or elements, make sure they handle DPI changes appropriately. Custom drawing and layout code may need adjustments to scale correctly with different DPI settings.
By handling the WM_DPICHANGED
message and adjusting the window size and other related factors, you can ensure your application adapts to DPI changes and maintains a consistent and visually pleasing user experience across different DPI settings on Windows.