DebugViewPP icon indicating copy to clipboard operation
DebugViewPP copied to clipboard

Persist window size/location

Open frostius opened this issue 3 years ago • 5 comments

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

frostius avatar May 02 '21 18:05 frostius

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 avatar May 02 '21 20:05 janwilmans

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.

janwilmans avatar May 02 '21 21:05 janwilmans

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 avatar May 02 '21 21:05 frostius

I just checked my code to see why I'm not seeing any similar issues. I use GetWindowPlacement and SetWindowPlacement w/o any coordinate translation and it appears to work fine even with multiple monitors at different DPIs. I do some additional checking to make sure the restoration is within valid bounds, but nothing DPI or scale related.

------ Original Message ------ From: "Jan Wilmans" @.> To: "CobaltFusion/DebugViewPP" @.> Cc: "Matt Frost" @.>; "Author" @.> Sent: 5/2/2021 5:29:51 PM Subject: Re: [CobaltFusion/DebugViewPP] Persist window size/location (#370)

I think the problem occurs because I take the coordinates of the window from 'GetWindowPlacement' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowplacement and compare them to coordinates from 'GetSystemMetrics' https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics and looking at the coordinates I get, they aren't working in the same coordinate-system.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CobaltFusion/DebugViewPP/issues/370#issuecomment-830875124, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5EK4SGYEP5T3MGGL5EWW3TLW747ANCNFSM437UKRWQ.

frostius avatar May 02 '21 22:05 frostius

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

janwilmans avatar May 03 '21 06:05 janwilmans

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?

vadz avatar Feb 21 '24 16:02 vadz

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

janwilmans avatar Feb 21 '24 18:02 janwilmans