public static string GetMonitorColorProfile(IntPtr hMonitor)
        {
            var profileDir = new StringBuilder(255);
            var pDirSize   = (uint)profileDir.Capacity;

            GetColorDirectory(null, profileDir, ref pDirSize);

            var mInfo = new MONITORINFOEX();

            mInfo.cbSize = (uint)Marshal.SizeOf(mInfo);
            if (!GetMonitorInfo(hMonitor, ref mInfo))
            {
                return(null);
            }

            var dd = new DISPLAYDEVICE();

            dd.cb = (uint)Marshal.SizeOf(dd);
            if (!EnumDisplayDevices(mInfo.szDevice, 0, ref dd, 0))
            {
                return(null);
            }

            WcsGetUsePerUserProfiles(dd.DeviceKey, CLASS_MONITOR, out bool usePerUserProfiles);
            var scope = usePerUserProfiles ? WcsProfileManagementScope.CURRENT_USER : WcsProfileManagementScope.SYSTEM_WIDE;

            if (!WcsGetDefaultColorProfileSize(scope, dd.DeviceKey, ColorProfileType.ICC, ColorProfileSubtype.NONE, 0, out uint size))
            {
                return(null);
            }

            var profileName = new StringBuilder((int)size);

            if (!WcsGetDefaultColorProfile(scope, dd.DeviceKey, ColorProfileType.ICC, ColorProfileSubtype.NONE, 0, size, profileName))
            {
                return(null);
            }
            return(System.IO.Path.Combine(profileDir.ToString(), profileName.ToString()));
        }
Example #2
0
 public static extern bool EnumDisplayDevices(
     string Device,                     // device name
     int iDevNum,                       // display device
     ref DISPLAYDEVICE lpDisplayDevice, // device information
     int dwFlags                        // reserved
     );
Example #3
0
 public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAYDEVICE lpDisplayDevice, uint dwFlags);