SetWindowPos with different scaling monitors sets position to a wrong location

486 views Asked by At

I have 2 monitors with different resolution and scaling:

  1. 2560 * 1440 scaling x1 (Primary)

  2. 1920 * 1200 scaling x1.5 (to the left from primary [2][1] aligned to top)

My application is changing position of another app window. The window I try to set location has dimensions 300x200. I set window location to (-150|200) and in the very next row check the location:

::SetWindowPos(this->handle, 0, lLeft, lTop, 0,0, SWP_NOREPOSITION | SWP_NOSIZE);
// output lLeft, lTop
RECT r = { 0 };
::GetWindowRect(this->handle, &r);
// output r.left, r.top

And I have following output:

<< -150  200 // SetWindowPos
>> -740  133 // GetWindowRect

After positioning the window has scaling 1 (from primary) while is located on secondary and should have scaling 1.5

It misplaces the window with x = [-150 ... 0]

It looks like this happens when the window is partially on secondary monitor and the middle point of the window already on primary monitor.

Is there anything I can do to avoid such behavior?

0

There are 0 answers