以编程方式启用显示

时间:2011-10-06 15:24:51

标签: c++ windows multiple-monitors

我正在尝试在C ++中启用辅助监视器。我有什么似乎尝试改变显示设置但没有真正发生,谁能告诉我哪里出错了?

    std::wstring devName( L"Intel(R) HD Graphics Family" );
    std::wstring dispName( L"\\\\.\\DISPLAY3" );

    DISPLAY_DEVICE theDisplay;
    theDisplay.cb = sizeof(theDisplay);
    DWORD dev = 0;

    while(EnumDisplayDevices(0, dev, &theDisplay, 0))
    {
        if (devName.compare(theDisplay.DeviceString) == 0 && dispName.compare(theDisplay.DeviceName) == 0)
        {
            // found display adapter we're looking for
            if (theDisplay.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
            {
                // Display is part of desktop, turn al other monitors off
                cout << "Display is part of desktop\n";
            }
            else
            {
                // Display is off, turn it on
                DEVMODE dm;

                memset(&dm,0,sizeof(DEVMODE));
                dm.dmSize = sizeof (DEVMODE);
                dm.dmFields = DM_POSITION;
                dm.dmPosition.x = 3361;
                dm.dmPosition.y = 0;
                dm.dmPelsWidth = 1920;
                dm.dmPelsHeight = 1080;

                LONG ret = ChangeDisplaySettingsEx (theDisplay.DeviceName, &dm, NULL, CDS_UPDATEREGISTRY, NULL);
                if (ret != DISP_CHANGE_SUCCESSFUL)
                {
                    cout << "failed";
                }
            }
        }
        dev++;
    }

    system ("pause");
    return 0;

0 个答案:

没有答案