0

I have a Windows application for which I want to save the window coordinates whenever the user resizes or moves it, except when those events are due to the window being minimized (the coordinates don't make sense then). My issue is that when the window gets minimized, the message WM_MOVE comes before WM_SIZE, and I can only detect minimization in the WM_SIZE case (using the test wParam == SIZE_MINIMIZED). Now I've noticed that the xy coordinates as given by GetWindowRect take the value -32000 in the minimized case, so I could test for that, but are those values reliable across different systems? Is there a better way?

Thank you!

1 Answer 1

0

SetWindowPlacement/GetWindowPlacement is the best way to restore/save window position.

If you absolutely don't want to remember the minimized state, if WINDOWPLACEMENT::showCmd is SW_SHOWMINIMIZED, change it to SW_SHOW before calling SetWindowPlacement.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm sticking to GetWindowRect because SetWindowPos is used in various locations in the code and as I understand the coordinate system differs from GetWindowPlacement. But I've still added a call to GetWindowPlacement just to check for the minimized state as you suggested, i.e. when showCmd == SW_SHOWMINIMIZED I can discard the coordinates. Thanks!
SetWindowPlacement knows about multiple monitors and that monitors can disappear, SetWindowPos/MoveWindow does not.
Hmm that's something to think about indeed!
WindowPlacement also knows how to ignore the snapped position, GetWindowRect does not. And WindowPlacement uses the workspace area meaning it knows how to interact with the taskbar and other appbars.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.