Search code examples
windowsapiwinapimultiple-monitorsnvapi

Which programming interface is used by windows-drivers for switching active displays


I have a notebook with VGA port and HDMI port. Therefore I'm able to switch between three displays with max. 2 displays active the same time.

I tried to find a way switching active displays programmatically using the Windows API or the .NET framework. But it seems to be impossible. According to other forum posts in the WWW this can only be achieved by using libraries which belong to the graphics card, e.g. the "AMD Display Library" (ADL) or the NVAPI for nVidia devices.

But I wonder how Windows is able to provide settings for switching monitors in the system settings, although there is no programming interface. Is Windows also using ADL / NVAPI?

Edit

As Deanna pointed out in the comments, there is probably no documented API for switching active displays. How are display driver developers able to know how to develop their drivers? What would be a reason for not making such things public available?


Solution

  • You should be able to do this using EnumDisplayDevices and ChangeDisplaySettingsEx passing CDS_SET_PRIMARY to select the monitor you want to use. Whether or not this provides the best interface I wouldn't know. Else you'd need to dig into the WDDM docs on multiple monitors listed here, the IViewHelper COM docs or the User-Mode display configuration API exposed by D3D.

    But I wonder how Windows is able to provide settings for switching monitors in the system settings, although there is no programming interface

    It should be noted that under Windows, the display drivers need to expose certain functions, to implement a low level API for the Windows kernel to use, allowing kernel to easily accomplish such tasks.

    How are display driver developers able to know how to develop their drivers? What would be a reason for not making such things public available?

    They would have specialized DDK's available to them* (here[XDDM|WDDM] are the MSDN docs on writing display drivers). the sort of API needed to easily swap around monitor output probably isn't public because very few people would need it, thus they would rather spend their time and money into fixed bugs in sections that are commonly used.

    *I would assume, though the public DDK has some ancient samples from 3dlabs for the implementation of display drivers, and the online docs are pretty comprehensive, but writing a full display driver is a major task, and would most likely need direct support from MS, which would probably need you to be an MS ISV or hardware partner.