How to find out whether a window was resized using Aero Snap feature? GetWindowPlacement
function gives the latest "restored" window size. I use it as follows:
WINDOWPLACEMENT wp = {};
wp.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement( hWnd, &wp );
For instance, it gives wp.rcNormalPosition = {top=208 bottom=520 left=152 right=510}
, when it should be
{top=0 bottom=1920 left=152 right=510}
.
Please, note that That was my fault, GetWindowRect
gives exactly the same incorrect result.GetWindowRect
gives the right result.
I need to save window state on the program exit and load it on start, so I need to know how windows are placed. How can I find out actual window coordinates?
Well, I made several tests with notepad.exe
(and some other standard Windows components) and it saves its state in the same way — it doesn't remember whether it was "snapped". So I suppose this is intended behavior of Windows programs.
AeroSnap is just another type of resize sent to your app by the window manager. As such you don't get to know that it was snap rather than any other type of resize.
The best you can hope for is to detect that opposite edges have been moved in the course of a size event. You'd need to check that height or width changed to so as to distinguish it from a move event.
The reason why you don't get told that this is a snap is that it's hard to imagine why an app would care what the mechanism for resizing is.
The comments have revealed more about your problem. You are trying to persist your apps position and size when the app closes down so that you can restore it when it restarts. You are using GetWindowPlacement()
to do so and have discovered that it returns an incorrect position when the last sizing of the Window was an Aero Snap.
My own app does exactly the same and I have encountered the exact same problem. The solution I used was to call GetWindowRect()
in place of GetWindowPlacement()
to obtain the window position and size. You state that this fails for you, in which case I have no idea what to suggest. I must say I find it a little hard to believe that GetWindowRect()
does not return the correct window rect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With