Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetWindowPos and multiple monitors with different resolutions

I have two monitors that are running at different resolutions. Left monitor is 1920x1200. Right monitor (the primary monitor) is 1920x1080.

I want to use SetWindowPos to make a window take up the full vertical height of the left hand monitor.

Here's what I do:

x = GetSystemMetrics(SM_XVIRTUALSCREEN);
hMonitor = monitorFromPoint(x, 0, MONITOR_DEFAULTTONEAREST);
MONITORINFO moninfo;
moninfo.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(hMonitor, moninfo);

height = moninfo.rcWork.bottom - moninfo.rcWork.top;

SetWindowPos(hwnd, 0, moninfo.rcWork.left, moninfo.rcWord.top, width, height, SWP_NOZORDER | SWP_NOACTIVATE);

I have confirmed that height is computing to 1200 (expected b/c that is the target monitor's vertical resolution).

However, after the call to SetWindowPos, the window rectangle doesn't fill the entire height of the screen (it is actually 1080 high).

I even tried this in VBA just for giggles:

Public Sub testSWP()
    Dim hwnd As Long
    hwnd = &H1D2F2C

    SetWindowPos &H1D2F2C, 0, -1900, 0, 150, 1200, SWP_NOZORDER Or SWP_NOACTIVATE
    Dim r As RECT
    GetWindowRect hwnd, r
    ' at this point, r.bottom = 1080
End Sub

This is well and good (GetWindowRect documentation says coordinates will be in Client space, and I'm assuming that win32 is translating between the resolution of my primary and secondary monitor.

I'm getting ready to inflate the vertical dimension by the ratio of the heights of the target and primary monitor. I'm pretty sure this is going to work, but it seems like a lot of hoops to have to jump through - am I maybe just not aware of a better way of determining the screen dimensions in 'client coordinates'?

like image 582
Kevin Day Avatar asked Nov 01 '22 02:11

Kevin Day


1 Answers

The issue isn't with coordinate transformation. It is that windows isn't allowing SetWindowPos to adjust the window so it is larger than the screen. Of course, it is basing this on the primary monitor size.

See: Can a window be resized past the screen size/offscreen?

like image 184
Kevin Day Avatar answered Dec 21 '22 11:12

Kevin Day