CobaltFusion / DebugViewPP

DebugView++, collects, views, filters your application logs, and highlights information that is important to you!
Boost Software License 1.0
978 stars 144 forks source link

Persist window size/location #370

Closed frostius closed 4 months ago

frostius commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

janwilmans commented 3 years ago

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 commented 4 months ago

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 commented 4 months ago

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