Reputation: 91
I want to programmatically switch between following two modes:
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
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:
Upvotes: 1
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:
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':
SetDisplayConfig()
To Extend the Display between two or more Displays (if displays are cloned), it is a little more trickier:
Extend PathInfoArray for one of the cloned displays to point to the Additional 'SourceModeInfo' - Item:
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
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