MoveWindow_() placement is slightly off?

Windows specific forum
highend
Enthusiast
Enthusiast
Posts: 169
Joined: Tue Jun 17, 2014 4:49 pm

MoveWindow_() placement is slightly off?

Post 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?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: MoveWindow_() placement is slightly off?

Post 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
Last edited by RASHAD on Sat Oct 22, 2022 10:56 pm, edited 1 time in total.
Egypt my love
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: MoveWindow_() placement is slightly off?

Post 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.
highend
Enthusiast
Enthusiast
Posts: 169
Joined: Tue Jun 17, 2014 4:49 pm

Re: MoveWindow_() placement is slightly off?

Post 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)...
Post Reply