Positioning a window in WPF (Top and Left Properties) with dpiAwareness in PerMonitorV2 mode
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
Hello,
For a WPF project in VB, I retrieve the mouse coordinates using a Hook mouse (MSLLHOOKSTRUCT) to display a window on the desktop according to the selection rectangle defined by the user.
I noticed that the mouse coordinates do not take into account the screen scales.
Is this normal?
So, I had to retrieve this scale using the GetDpiForMonitor API and created a manifest file with DPI recognition per screen.
PerMonitorV2 .
In a test project, I noticed problems with the bad positioning of my window in relation to the placement request.
Here are my tests with the Left property of a window:
Screen resolution 1: 1680x1050
Screen resolution 2: 1600x900
Screen 1 = 100% - Screen 2 = 150%.**
Window on screen 1, asks to switch to screen 2
Ask left = 1680 after moving : left = 1120 on screen 2
The left was divided by 1.5 after the move.
Window on screen 2, asks to switch to screen 1
Ask left = 100 after moving : left = 150 on screen 1
The left was multiplied by 1.5 after the move.
Screen 1 = 150% - Screen 2 = 100%.
Window on screen 1, asks to switch to screen 2
Ask left = 1680 after moving : left = 2520 on screen 2
The left was multiplied by 1.5 after the move.
Window on screen 2, asks to switch to screen 1
Ask left = 100 after moving : left = 66.66 on screen 1
The left was divided by 1.5 after the move.
Is this management of the values of the positioning properties correct?
These requested positions do not correspond to the physical position where I want to place my window.
Without DPI recognition per screen, the positioning of the window respects the requested coordinates. The Top and Left properties do not change despite the different scales.
You can perform the test using the program contained in the zip file.

[WpfApp2.zip](https://github.com/dotnet/wpf/files/4751287/WpfApp2.zip)
Contributor guide
Assessment
This issue has not been assessed yet.