title: Enumerating monitors on a computer
body: <p>I have found 7 different ways to enumerate the monitors attached to the computer. But all solutions give different results (number of the monitors and information on each monitor).</p>
  
  <p>These solutions are:</p>
  
  <ol>
  <li><p>Using the famous <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162609(v=vs.85).aspx" rel="noreferrer"><code>EnumDisplayDevices</code></a></p></li>
  <li><p>Using <a href="http://msdn.microsoft.com/library/windows/desktop/dd162610.aspx" rel="noreferrer"><code>EnumDisplayMonitors</code></a></p></li>
  <li><p>Using the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582(v=vs.85).aspx" rel="noreferrer"><em>Windows Management Instrumentation (WMI)</em></a>:<br/>
  With the following query: <code>SELECT * FROM WmiMonitorID</code> in the <code>root\\WMI</code> namespace.</p></li>
  <li><p>Again using the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582(v=vs.85).aspx" rel="noreferrer"><em>WMI</em></a>:<br/>
  With the new query: <code>SELECT * FROM Win32_DesktopMonitor</code> in the <code>root\\CIMV2</code> namespace.</p></li>
  <li><p>Using the <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff550855(v=vs.85).aspx" rel="noreferrer"><em>Setup API</em></a>:<br/>
  By first calling <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff551069(v=vs.85).aspx" rel="noreferrer"><code>SetupDiGetClassDevs</code></a> to retrieve the device information set then, iterating with <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff551010(v=vs.85).aspx" rel="noreferrer"><code>SetupDiEnumDeviceInfo</code></a></p></li>
  <li><p>Using the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205075(v=vs.85).aspx" rel="noreferrer"><em>DirectX Graphics Infrastructure (DXGI)</em></a><br/>
  With first <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174538(v=vs.85).aspx" rel="noreferrer"><code>IDXGIFactory::EnumAdapters</code></a>, then <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174525(v=vs.85).aspx" rel="noreferrer"><code>IDXGIAdapter::EnumOutput</code></a></p></li>
  <li><p>Using the <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff539590(v=vs.85).aspx" rel="noreferrer"><em>Connecting and Configuring Displays (CCD) APIs</em></a>:<br/>
  <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff569215(v=vs.85).aspx" rel="noreferrer"><code>QueryDisplayConfig</code></a><code>(QDC_ALL_PATHS, &amp;numPathArrayElements, pathInfoArray, &amp;numModeInfoArrayElements, modeInfoArray, nullptr);</code></p></li>
  </ol>
  
  <p>I've tried to understand precisely the difference between all theses methods with the MSDN reference, in vain.</p>
  
  <h2>Observations</h2>
  
  <p>From what I've observed:</p>
  
  <ul>
  <li>The <em>WmiMonitorID</em> and <em>Setup API</em> queries return the list of connected (not necessarily active) displays.</li>
  <li>The <em>Win32_DesktopMonitor WMI</em> query returns <em>wrong</em> (at least unexpected) result (only 1 monitor enumerated even when inactive and desktop on another monitor). </li>
  <li><em>EnumDisplayDevices</em> returns the list of active devices (except when only 1 monitor is active with other monitor connected)</li>
  <li><em>EnumDisplayMonitors</em> and <em>DXGI</em> queries return the list of active monitors.</li>
  <li><em>CCD</em> seems to be the most reliable method (gives all possible paths between targets and sources).</li>
  </ul>
  
  <h2>Questions</h2>
  
  <p>What result should I really expect when using each of these methods (list of connected displays, list of installed displays, list of active displays)? What if I use Mirrored displays or Extended displays? What if the computer has multiple graphics cards without multiple outputs?</p>
  
  <p>Bonus: Some methods (<em>DXGI</em>, <em>EnumDisplayDevices</em>, <em>CCD</em>) use a kind of hierarchy with <em>Adapter</em>-<em>Monitor</em>. But doesn't give the same links between Adapters and Monitors. So, what is the définition of an adapter for <em>DXGI</em>? for <em>CCD</em>? for <em>EnumDisplayDevices</em>?</p>