Page 1 of 1

MoveWindow_() placement is slightly off?

Posted: Sat Oct 22, 2022 9:12 pm
by highend
Hi,

On Windows 10:

Code: Select all

MoveWindow_(GetForegroundWindow_(), 0, 0, 1920, 1560, 1)
My main screen has a 3840 x 1600 resolution.

I want to place a window on the exact half left side.
1560 because the taskbar is currently 40 px high.

I'm using this on e.g. Notepad.exe

but after the move is done, the x position isn't 0, it's actually 8
y is 0, so that's fine.
The rightmost position is 1912, so it's also 8 px less that it should be
and finally the height is also 8 px less than expected.

Is this typical behavior and is there a formula to know how to correct this "skew"?

Btw, WIN + Left, Right, etc. hotkeys do it correctly, the positions and sizes of windows moved by these are correct so there must be some way to get the skew values?

Re: MoveWindow_() placement is slightly off?

Posted: Sat Oct 22, 2022 10:39 pm
by RASHAD
Hi
It looks like you did not consider your window borders
For example try :

Code: Select all

OpenWindow(0,0,0,800,600,"Test",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
AdjustWindowRectEx_(r.RECT,#PB_Window_SystemMenu|#PB_Window_SizeGadget,0,0)
border = r\right
Debug border

Re: MoveWindow_() placement is slightly off?

Posted: Sat Oct 22, 2022 10:40 pm
by Mijikai
From the nets (maybe also relevant):
In Windows Vista and later, the Window Rect now includes the area occupied by the drop shadow.
So, function MoveWindow and SetWindowPos think that the position/size you pass includes the shadow.
If you want to move and resize the area that excludes the shadow, then you need to first calculate the size of the shadow.

Re: MoveWindow_() placement is slightly off?

Posted: Sat Oct 22, 2022 11:53 pm
by highend
Thanks!

I'll need to get the dwStyle for that external window first [GetWindowLong_(hWnd, #GWL_STYLE)] and with this value I can use AdjustWindowRectEx_() and then adapt the offsets for the real size of the window :mrgreen:

Works nicely with two Notepad.exe windows (one moved to the left half of the screen and the other one moved to the right side)...