h4kun4m4t4t4
h4kun4m4t4t4

Reputation: 91

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.

Upvotes: 4

Views: 2295

Answers (3)

Aleksa
Aleksa

Reputation: 11

Whole story about duplicating multiple monitors on win 10 is related to setting up target monitor's x and y position to the one found in the source monitor. So, first:

  • go through the list of all paths, and find indices for source and target monitor (it is good to take only those that are active)
  • get x and y position from the source monitor (from mode array - i.e., DISPLAYCONFIG_MODE_INFO)
  • set target monitor x and y position taken from source
  • create new display paths array containing only active paths (it is easy upper active array put into new one.
  • call SetDisplayConfig with new path array and existing modes (take into account size of mode and path array

Upvotes: 1

h4kun4m4t4t4
h4kun4m4t4t4

Reputation: 91

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 :-( )

Upvotes: 4

Isaack Rasmussen
Isaack Rasmussen

Reputation: 457

How about changing the primary display first and then SetDisplayConfig()?

ChangeDisplaySettingsEx with CDS_SET_PRIMARY https://msdn.microsoft.com/en-us/library/windows/desktop/dd183413(v=vs.85).aspx

And then you call SetDisplayConfig to clone.

Upvotes: 1

Related Questions