How to Convert this DPI Matrix transform code into C++?

MERUN KUMAR MAITY 636 Reputation points
2021-09-25T18:42:56.343+00:00

Here is the code -

public class DpiDecorator : Decorator
     {
         public DpiDecorator()
         {
             this.Loaded += (s, e) =>
             {
                 System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
                 ScaleTransform dpiTransform = new ScaleTransform(1 / m.M11, 1 / m.M22);
                 if (dpiTransform.CanFreeze)
                     dpiTransform.Freeze();
                 this.LayoutTransform = dpiTransform;
             };
         }
     }
Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2021-09-26T08:22:25.317+00:00

    This code is for WPF
    You can find the same code (less compacted, in different functions) in MS C++ sample : PerMonitorDPIWindow.cpp


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.