GetWindowPlacement gives incorrect window position

How do I know if a window has been resized using the Aero Snap feature ? GetWindowPlacement gives the last "restored" window size. I use it as follows:

 WINDOWPLACEMENT wp = {}; wp.length = sizeof(WINDOWPLACEMENT); ::GetWindowPlacement( hWnd, &wp ); 

For example, it gives wp.rcNormalPosition = {top=208 bottom=520 left=152 right=510} when it should be {top=0 bottom=1920 left=152 right=510} .

Note that GetWindowRect gives exactly the same wrong result. It was my mistake, GetWindowRect gives the correct result.

I need to save the state of the window at the output of the program and load it at startup, so I need to know how the windows are installed. How to find out the actual coordinates of the window?


Well, I did some tests with notepad.exe (and some other standard Windows components), and it maintains its state in the same way as - it doesn’t remember if it was "cut off". Therefore, I assume that this is the intended behavior of Windows programs.

+6
source share
1 answer

AeroSnap is another type of resize sent by your window manager application. This way, you won’t recognize that it was a binding, and not some other type of resizing.

The best you can hope for is to find that the opposite edges were moved during the size event. You will need to check if the height or width has changed to distinguish it from the move event.

The reason you are not told that this is fast is because it is hard to imagine why the application will care about what the resizing mechanism is.


Comments more revealed your problem. You are trying to maintain your position and size of the applications when the application closes in order to restore it upon restart. You use GetWindowPlacement() for this and find that it returns the wrong position when the last window size was Aero Snap.

My own application works the same way, and I ran into the same problem. The solution I used was to call GetWindowRect() instead of GetWindowPlacement() to get the position and size of the window. You declare that this is not suitable for you, and in this case I have no idea what to offer. I must say, it’s hard for me to believe that GetWindowRect() does not return the correct rect window.

+7
source

Source: https://habr.com/ru/post/885959/


All Articles