Search code examples
cwinapidpimultiple-monitors

Not getting the WM_DPICHANGED notification


I have a Win32 application where I have implemented a groupWndProc() callback and I'm getting the notifications except for WM_DPICHANGED.

I have two monitors connected: one regular and one 4k. I expect to get the notification when moving the application from one monitor to another.


Solution

  • Make sure your process is DPI aware using SetProcessDpiAwareness with Process_Per_Monitor_DPI_Aware and according to the tutorial on msdn you must call this before creating your windows. Make sure your monitors when queried return different dpis using GetDpiForMonitor.

    For reference check the High DPI Reference.

    Alternatively setup an application manifest as per this tutorial. Add a dpiAware element to your application manifest:

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
      <asmv3:application>
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
          <dpiAware>True/PM</dpiAware>
        </asmv3:windowsSettings>
      </asmv3:application>
    </assembly>
    

    and make sure your compiler includes the manifest: add the manifest file to Project properties -> Configuration properties -> Manifest Tool -> Additional Manifest Files.