Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiMonitorSetup: Duplicate Desktop between secondary monitors programmatically

I want to programmatically switch between following two modes:

example image

I already tried to use the SetDisplayConfig Function, but failed. With following command it is possible to clone the main monitor to all attached displays:

SetDisplayConfig(0, null, 0, null, 
    SetDisplayConfigFlags.SDC_TOPOLOGY_CLONE | SetDisplayConfigFlags.SDC_APPLY);

Unfortunately I need to duplicate secondary monitors!

I found another approach in question How to make clone or extended mode. But I can't getting it working to set the source for different display to the same reference.

like image 223
h4kun4m4t4t4 Avatar asked Sep 07 '25 02:09

h4kun4m4t4t4


1 Answers

Working Solution for Windows 7:

To clone/duplicate the desktop between two (or more) connected devices, all you have to do is to:

  1. QueryDisplayConfig()
  2. Share the 'sourceInfo.id' and 'sourceInfo.modeInfoIdx' for all 'PathInfoArray'-Items which you want to duplicate the desktop. e.g. duplicate display 'index 1' to Display with Index '2 and 3':

    • PathInfoArray[2].sourceInfo.id = PathInfoArray[1].sourceInfo.id
    • PathInfoArray[2].sourceInfo.modeInfoIdx = PathInfoArray[1].sourceInfo.modeInfoIdx
    • PathInfoArray[3].sourceInfo.id = PathInfoArray[1].sourceInfo.id
    • PathInfoArray[3].sourceInfo.modeInfoIdx = PathInfoArray[1].sourceInfo.modeInfoIdx
  3. SetDisplayConfig()


To Extend the Display between two or more Displays (if displays are cloned), it is a little more trickier:

  1. QueryDisplayConfig()
  2. Add a 'SourceModeInfo' Item with infoType 'Source' foreach additional Clone Display to the 'SourceModeInfoArray': If two Displays configured you need one additionaly 'SourceModeInfo' Item (if three were cloned => 2 Items, and so on)
  3. Extend PathInfoArray for one of the cloned displays to point to the Additional 'SourceModeInfo' - Item:

    • PathInfoArray[2].sourceInfo.id = AddItem.sourceInfo.id;
    • PathInfoArray[2].sourceInfo.modeInfoIdx = AddItem.sourceInfo.modeInfoIdx;
  4. SetDisplayConfig()

This just works for Win7.


On Windows 10 RS1 onwards the SetDisplayConfig() will fail with invalid parameter. I'm not quite sure why, but i recognized that under Windows 10 the 'ModeInfo.adapterId' (low and high part) changes on each reboot. Additonaly the adapter changes when you duplicate/extend via "Windows-Settings -> Display". That's why I believe under Windows 10 you have to adjust the adapterid for PathModeInfoArray and SourceModeInfoArray as well.

Problem for now: I don't know how to get the right Adapter id for that purpose. I would be very appreciate if anyone has an answer/tip for solving this problem under windows 10. (I need a working solution for windows 10 :-( )

like image 130
h4kun4m4t4t4 Avatar answered Sep 08 '25 23:09

h4kun4m4t4t4