SetConsoleWindowInfo on Multiple monitors
Asked Answered
P

1

10

OS: Windows 7 64bit

Two monitors, one in portrait, one in landscape. Landscape one is primary.

I'm trying to resize a console using SetConsoleWindowInfo, but if I try and resize it to a size that would fit on the portrait monitor but not the landscape (primary) monitor, the function returns as failed, even though the console is actually on the portrait monitor.

I know Windows uses the screen size as an upper limit on the dimensions of the console window. However, it is only using the screen size of the primary monitor. Is there any way to specify which screen's dimensions to use, or even better, to have it use the combined desktop area as the maximum dimensions?

Plantagenet answered 22/5, 2011 at 1:40 Comment(2)
+1 -- The docs seem to indicate that the GetLargestConsoleWindowSize function is used to determine things, in which case you're SOL. :(Faggoting
so no way around this outside of recoding the entire console windowing system?Plantagenet
T
2

The following might help:

#include "windows.h"
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    bool hasSecondary = false;
    POINT secondaryPosition;
    POINT secondarySize;
    POINT primarySize;
    {
        DISPLAY_DEVICE displayDevice;
        displayDevice.cb = sizeof(DISPLAY_DEVICE);

        DEVMODE deviceMode;
        ZeroMemory(&deviceMode, sizeof(DEVMODE));
        deviceMode.dmSize = sizeof(DEVMODE);

        int i = 0;
        while(::EnumDisplayDevices(NULL, i++, &displayDevice, 0))
        {
            if(displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP &&
                !(displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
            {
                if(EnumDisplaySettingsEx(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &deviceMode, 0) == FALSE)
                    EnumDisplaySettingsEx(displayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &deviceMode, 0);
                if(deviceMode.dmPosition.x != 0 || deviceMode.dmPosition.y != 0)
                {
                    hasSecondary = true;
                    secondaryPosition.x = deviceMode.dmPosition.x;
                    secondaryPosition.y = deviceMode.dmPosition.y;
                    secondarySize.x = deviceMode.dmPelsWidth;
                    secondarySize.y = deviceMode.dmPelsHeight;
                }
                else
                {
                    primarySize.x = deviceMode.dmPelsWidth;
                    primarySize.y = deviceMode.dmPelsHeight;
                }
            }
        }
    }

    MoveWindow(GetConsoleWindow(),
        secondaryPosition.x, secondaryPosition.y,
        secondarySize.x, secondarySize.y,
        TRUE);

    _getch();

    return 0;
}
Tiossem answered 15/6, 2011 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.