Question

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'?

Was it helpful?

Solution

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?

OTHER TIPS

Do you want a normal window (with titlebar etc) or do you want a fullscreen window (like youtube fullscreen video playback or games).

I think you want the latter i.e. make a fullscreen window which covers the entire screen. For that, in the call to CreateWindow, pass WS_POPUP as the window style (see dwStyle param). This will create the window without the titlebar and it will cover the entire screen.

Also, I don't think the way you're getting the left monitor is correct. You should be using EnumMonitors to iterate through all the monitors, get the left most monitor and then use GetMonitorInfo to retrieve the monitor's rects if you want to make this a generic application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top