Persist window size/location
Closed this issue · 7 comments
I can see it now also, it seems to happen when you put it exactly on the limit at the edge of the screen.
I think the problem occurs because I take the coordinates of the window from 'GetWindowPlacement' and compare them to coordinates from 'GetSystemMetrics' and looking at the coordinates I get, they aren't working in the same coordinate-system.
If I remember right, all the coordinates need to be in the same scale (DPI) as the primary monitor. GetScaleFactorForMonitor is what I use to convert dimensions
All coordinates are in pixels so no scaling is involved, but I use 'GetSystemMetrics' to know whether the stored coordinates are actually visible right now.
for example, if you have two monitors the 'virtual screen' size might be (-1920,0) - (1920,1200), but if one monitor is disconnected, half of the virtual screen's coordinates is now an 'off screen' location.
I have had complains in the past of 'debugview not showing', and this was the cause. So the prevent that I check the 'visibility' of the coordinates before restoring the window's position.
It not appears that the coordinates returned by GetSystemMetrics are not exactly aligned with the numbers coming from GetWindowPlacement...
This is where the positions are stored:
https://github.com/CobaltFusion/DebugViewPP/blob/master/DebugView%2B%2B/MainFrame.cpp#L760
and here we read/check/set them:
https://github.com/CobaltFusion/DebugViewPP/blob/master/DebugView%2B%2B/MainFrame.cpp#L684
FWIW the code linked above is wrong because GetWindowPlacement()
takes the DPI into account and returns results adjusted for it, i.e. divided by 2 at 200% scaling, but GetSystemMetrics()
does not (there is GetSystemMetricsForDpi()
which does).
I should be able to make a PR to fix this, if this project still accepts them?
sure, I would love a PR, the project files may be a little out of date, let me know if you need me to update them first