My problem is to turn off the monitor using ChangeDisplaySettingsEx . I think this is not rocket science, but after some digging it still seems impossible. I found a way to disable all secondary displays based on the sample Microsoft code found here . Although only basic configuration was required to work, re-installation never worked. I tried to do this:
1. Initialize DisplayDevice
BOOL FoundSecondaryDisp = FALSE; DWORD DispNum = 0; DISPLAY_DEVICE DisplayDevice; LONG Result; TCHAR szTemp[200]; int i = 0; DEVMODE defaultMode; ZeroMemory(&DisplayDevice, sizeof(DisplayDevice)); DisplayDevice.cb = sizeof(DisplayDevice);
2. Find all devices
while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) { ZeroMemory(&defaultMode, sizeof(DEVMODE)); defaultMode.dmSize = sizeof(DEVMODE);
3. Detecting a disconnected device
if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
4. Turn on the device
DEVMODE DevMode; ZeroMemory(&DevMode, sizeof(DevMode)); DevMode.dmSize = sizeof(DevMode); DevMode.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT; DevMode.dmPelsWidth = 1920; DevMode.dmPelsHeight = 1080; Result = ChangeDisplaySettingsEx(DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); ChangeDisplaySettingsEx(NULL, NULL, NULL, NULL, NULL);
The last point returns the code DISP_CHANGE_FAILED and does not turn on the display. Has anyone had a similar experience?
source share