Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically changing the "presentation display mode"

The presentation display modes are those you see when using the Windows+p shortcut:

  1. Computer Only
  2. Duplicate
  3. Extend
  4. Projector Only

Do any API calls exist which allow one to switch between these display modes?

I want to programmatically switch between monitor and HDMI TV (and do a bunch of other things simultaneously, hence Windows+p not being useful), but I'm hitting a brick wall.

like image 316
Lee John Moore Avatar asked May 28 '13 10:05

Lee John Moore


2 Answers

You can obtain and change the display setting using EnumDisplaySettingsEx and ChangeDisplaySettingsEx:

The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode.

Check this Codeproject project and this Stackoverflow question for example code

like image 70
dsfgsho Avatar answered Oct 31 '22 13:10

dsfgsho


You can set the desktop display mode with SetDisplayConfig() eg.

SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTERNAL | SDC_APPLY);

You can retrieve the current display mode with QueryDisplayConfig(). eg.

DISPLAYCONFIG_TOPOLOGY_ID currentTopology;
QueryDisplayConfig(QDC_DATABASE_CURRENT, &PathArraySize, PathArray, &ModeArraySize, ModeArray, &currentTopology);

(Related source for this call here)

This is for C++. C# would require DLL imports.

like image 28
Greg Avatar answered Oct 31 '22 11:10

Greg