Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist window size/location #370

Closed
frostius opened this issue May 2, 2021 · 7 comments
Closed

Persist window size/location #370

frostius opened this issue May 2, 2021 · 7 comments
Assignees

Comments

@frostius
Copy link

frostius commented May 2, 2021

DebugView++ v1.8.0.103
Win 10 18363
Monitors: single 4K monitor

App window size/location is not persisting reliably.
See attached gif containing app version and example of non-persistence

persist

@janwilmans
Copy link
Member

I can see it now also, it seems to happen when you put it exactly on the limit at the edge of the screen.

@janwilmans
Copy link
Member

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.

@frostius
Copy link
Author

frostius commented May 2, 2021

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

@frostius
Copy link
Author

frostius commented May 2, 2021 via email

@janwilmans
Copy link
Member

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

@vadz
Copy link
Contributor

vadz commented Feb 21, 2024

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?

@janwilmans
Copy link
Member

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

vadz added a commit to vadz/DebugViewPP that referenced this issue Feb 21, 2024
The coordinates returned by GetWindowPlacement() must be passed to
SetWindowPlacement() and not SetWindowPos() as the former functions
account correctly for non-standard DPI, while the latter one does not.

Using SetWindowPlacement() also allows to remove the checks for the
coordinates being valid because the function already checks for this and
will always position the window inside the visible area anyhow.

Fixes CobaltFusion#370.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants