Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetConsoleWindowInfo on Multiple monitors

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?

like image 390
tentonwire Avatar asked May 22 '11 01:05

tentonwire


1 Answers

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;
}
like image 104
wxffles Avatar answered Nov 12 '22 16:11

wxffles