How to set Display Settings to EXTEND mode in Windows 7 using C++?

后端 未结 1 365
一生所求
一生所求 2020-12-17 06:45

In my C++ Win32 program I want to set the current Display Settings to \"Extend\" mode. I Googled and found out that SetDisplayConfig() is the way to go forward in Windows 7

相关标签:
1条回答
  • 2020-12-17 07:45

    Okay so I figured out the answer.

    To identify the current configuration:

    UINT32 PathArraySize = 0;
    UINT32 ModeArraySize = 0;
    DISPLAYCONFIG_PATH_INFO* PathArray;
    DISPLAYCONFIG_MODE_INFO* ModeArray;
    DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;
    
    GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
    
    PathArray =   (DISPLAYCONFIG_PATH_INFO*)malloc(PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
    memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
    
    ModeArray =   (DISPLAYCONFIG_MODE_INFO*)malloc(ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
    memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
    
    LONG ret = QueryDisplayConfig(QDC_DATABASE_CURRENT,&PathArraySize, PathArray, &ModeArraySize, ModeArray, &CurrentTopology);
    // Above CurrentTopology variable will aquire the current display setting (ie Extend, Duplicate etc)
    
    free(PathArray);
    free(ModeArray);
    

    To set the required display setting (Extend, Duplicate etc):

    SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_EXTEND|SDC_APPLY);
    

    or

    SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_CLONE|SDC_APPLY);
    
    0 讨论(0)
提交回复
热议问题