c++ - Attach disabled display device with WinAPI -
my problem enabling disabled monitor changedisplaysettingsex
. guess not rocket science after digging still looks impossible. found way disable secondary displays basing on microsoft code sample found here. while needed basic tweaking work, re-attaching never worked. trying was:
1. initialize displaydevice
bool foundsecondarydisp = false; dword dispnum = 0; display_device displaydevice; long result; tchar sztemp[200]; int = 0; devmode defaultmode; zeromemory(&displaydevice, sizeof(displaydevice)); displaydevice.cb = sizeof(displaydevice);
2. find devices
while (enumdisplaydevices(null, dispnum, &displaydevice, 0)) { zeromemory(&defaultmode, sizeof(devmode)); defaultmode.dmsize = sizeof(devmode); //point 3 goes here }
3. detect detached device
if (!(displaydevice.stateflags & display_device_attached_to_desktop))
4. enable 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);
last point returns disp_change_failed code , not enable display. did have similar experience?
Comments
Post a Comment