Win32 C++ - Check if the Window PositionX/Position

2019-03-06 19:31发布

问题:

It is possible to check whenever the X/Y position of the window changed? Also, if it's possible to check if the Window Width/Height changed too.

回答1:

You're looking for the WM_MOVE and WM_SIZE messages.



回答2:

As already answered, you can handle WM_SIZE and WM_MOVE. But you can also intercept the messages before they have any effect by checking WM_WINDOWPOSCHANGING (except in the case where a call to SetWindowPos passes SWP_NOSENDCHANGING - but that is usually deliberate and completely under your control). This message is useful for cleanly handling window size/position restrictions or doing window snapping. If you force stuff to happen during WM_SIZE or WM_MOVE you will get flickering etc.