Windows 7 Windows 7 New API Configuring & Connecting Displays (CCD) Scripting

JTS000ID

New Member
Joined
Apr 14, 2011
Messages
2
Requirement: Enable/Disable mirroring (also called cloning) between multiple monitors programatically.

Platform: Windows 7 onwards

Research: So far I've come across Windows 7 new API called CCD Link Removed - Invalid URL In the draft it says to deliver what I need.

Problem: I don't know how to write a CCD script and Windows doesn't tell that either on their website.

What I need: I need to know how to set-up/write a CCD script. Is it a .bat format? Any example resource would be really appreciated.
 
Solution
To programmatically enable/disable mirroring (cloning) between multiple monitors on Windows 7 and newer versions, you can use the Windows Display Driver Model (WDDM) and the Graphics Device Interface (GDI) functions to manipulate display settings. The CCD API (Customizable Customization Data) is indeed part of this process. Here's a basic outline of how you can achieve this using PowerShell scripting:
  1. Use PowerShell Scripting:
    • PowerShell provides access to WMI (Windows Management Instrumentation) classes that can be used to manipulate display settings.
    []Example PowerShell Script:
    • Here's a basic example that enables or disables mirroring between monitors:
Code:
# Enable Mirroring Add-Type...
To programmatically enable/disable mirroring (cloning) between multiple monitors on Windows 7 and newer versions, you can use the Windows Display Driver Model (WDDM) and the Graphics Device Interface (GDI) functions to manipulate display settings. The CCD API (Customizable Customization Data) is indeed part of this process. Here's a basic outline of how you can achieve this using PowerShell scripting:
  1. Use PowerShell Scripting:
    • PowerShell provides access to WMI (Windows Management Instrumentation) classes that can be used to manipulate display settings.
    []Example PowerShell Script:
    • Here's a basic example that enables or disables mirroring between monitors:
Code:
# Enable Mirroring Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class DisplaySettings { [DllImport("user32.dll")] public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode); [DllImport("user32.dll")] public static extern int ChangeDisplaySettings(ref DEVMODE devMode, int flags); [StructLayout(LayoutKind.Sequential)] public struct DEVMODE { private const int CCHDEVICENAME = 32; private const int CCHFORMNAME = 32; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)] public string dmDeviceName; public short dmSpecVersion; public short dmDriverVersion; public short dmSize; public short dmDriverExtra; public int dmFields; public int dmPositionX; public int dmPositionY; public int dmDisplayOrientation; public int dmDisplayFixedOutput; public short dmColor; public short dmDuplex; public short dmYResolution; public short dmTTOption; public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)] public string dmFormName; public short dmLogPixels; public int dmBitsPerPel; public int dmPelsWidth; public int dmPelsHeight; public int dmDisplayFlags; public int dmDisplayFrequency; public int dmICMMethod; public int dmICMIntent; public int dmMediaType; public int dmDitherType; public int dmReserved1; public int dmReserved2; public int dmPanningWidth; public int dmPanningHeight; } public const int ENUM_CURRENT_SETTINGS = -1; public const int CDS_UPDATEREGISTRY = 0x01; public const int CDS_TEST = 0x02; public const int DISP_CHANGE_SUCCESSFUL = 0; public const int DISP_CHANGE_BADDUALVIEW = -6; public static DEVMODE GetDisplaySettings(int iDevNum) { DEVMODE dm = new DEVMODE(); dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE)); EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref dm); return dm; } public static void SetDisplayMode(DEVMODE devMode) { ChangeDisplaySettings(ref devMode, CDS_TEST); ChangeDisplaySettings(ref devMode, CDS_UPDATEREGISTRY); } } "@ # Get the current display settings $devMode = [DisplaySettings]::GetDisplaySettings(0) # Modify the settings to enable mirroring $devMode.dmPelsWidth = 1920 $devMode.dmPelsHeight = 1080 # Set the new display mode [DisplaySettings]::SetDisplayMode($devMode)
This script is a starting point and might need adjustments based on your specific requirements and monitor configurations.
  1. Save the Script:
    • Save this script with a .ps1 extension, which is the extension for PowerShell scripts.
    [
  1. ]Run the Script:
    • You can run the PowerShell script by opening PowerShell as an administrator and executing it. Remember to test this script first on a test system to ensure it behaves as expected before deploying it on your production systems.
 
Solution