public static DisplayTopology GetDisplayTopology() { uint numPathArrayElements = 0; uint numModeInfoArrayElements = 0; NativeMethods.GetDisplayConfigBufferSizes( QueryDisplayFlags.DatabaseCurrent, out numPathArrayElements, out numModeInfoArrayElements ); var pathArray = new DisplayConfigPathInfo[numPathArrayElements]; var modeArray = new DisplayConfigModeInfo[numModeInfoArrayElements]; DisplayConfigTopologyId displayTopology; NativeMethods.QueryDisplayConfig( QueryDisplayFlags.DatabaseCurrent, out numPathArrayElements, pathArray, out numModeInfoArrayElements, modeArray, out displayTopology ); switch( displayTopology ) { case DisplayConfigTopologyId.External: return DisplayTopology.External; case DisplayConfigTopologyId.Internal: return DisplayTopology.Internal; case DisplayConfigTopologyId.Extend: return DisplayTopology.Extend; } return DisplayTopology.Clone; }
/// <summary> /// This method can be used in order to filter out specific paths that we are interested, /// a long with their corresponding paths. /// </summary> /// <param name="pathType"></param> /// <param name="topologyId"></param> /// <returns></returns> public static IEnumerable<DisplayConfigPathWrap> GetPathWraps( QueryDisplayFlags pathType, out DisplayConfigTopologyId topologyId) { topologyId = DisplayConfigTopologyId.Zero; int numPathArrayElements; int numModeInfoArrayElements; var status = Wrapper.GetDisplayConfigBufferSizes( pathType, out numPathArrayElements, out numModeInfoArrayElements); if (status != StatusCode.Success) { // TODO; POSSIBLY HANDLE SOME OF THE CASES. var reason = string.Format("GetDisplayConfigBufferSizesFailed() failed. Status: {0}", status); throw new Exception(reason); } var pathInfoArray = new DisplayConfigPathInfo[numPathArrayElements]; var modeInfoArray = new DisplayConfigModeInfo[numModeInfoArrayElements]; // topology ID only valid with QDC_DATABASE_CURRENT var queryDisplayStatus = pathType == QueryDisplayFlags.DatabaseCurrent ? Wrapper.QueryDisplayConfig( pathType, ref numPathArrayElements, pathInfoArray, ref numModeInfoArrayElements, modeInfoArray, out topologyId) : Wrapper.QueryDisplayConfig( pathType, ref numPathArrayElements, pathInfoArray, ref numModeInfoArrayElements, modeInfoArray); ////////////////////// if (queryDisplayStatus != StatusCode.Success) { // TODO; POSSIBLY HANDLE SOME OF THE CASES. var reason = string.Format("QueryDisplayConfig() failed. Status: {0}", queryDisplayStatus); throw new Exception(reason); } var list = new List<DisplayConfigPathWrap>(); foreach (var path in pathInfoArray) { var outputModes = new List<DisplayConfigModeInfo>(); foreach (var modeIndex in new[] { path.sourceInfo.modeInfoIdx, path.targetInfo.modeInfoIdx }) { if (modeIndex < modeInfoArray.Length) outputModes.Add(modeInfoArray[modeIndex]); } list.Add(new DisplayConfigPathWrap(path, outputModes)); } return list; }
/// <summary> /// Initializes new structure. Having constructor for struct makes it immutable. /// </summary> /// <param name="path"></param> /// <param name="modeInfo"></param> public DisplayConfigPathWrap(DisplayConfigPathInfo path, IEnumerable<DisplayConfigModeInfo> modeInfo) : this() { Path = path; Modes = modeInfo; }