Search code examples
c++direct2d

Direct2D WM_MOUSEMOVE message with scaled display


I am new to Direct2D programming and I have encountered an issue with the WM_MOUSEMOVE message handling.

As documented in MSDN, I should use this enum to handle the mouse move, and should use the LOWORD & HIWORD to extract the current x and y coordinates.

That works fine when I am working on a normal display, but when trying to run it on scaled displays (e.g. 125% in my case), the values of x and y aren't accurate, in other words, there is an "indentation" between the current position of the mouse and the values extracted from lparam.

I guess I should query the OS or the window to get the current scaling so I can calculate the right position, but don't know how!

any help please?


Solution

  • You can take control of the scaling by declaring your program as DPI aware. Then the automatic scaling will stop and you'll get the original coordinates. You'll need to scale the window yourself though.

    Creating a DPI-Aware Application