Win 7 using WDDM display driver.
Trying to enable a particular secondary monitor(with ID = Id) in case of multiple monitors configured.
dwStatus = GetDisplayConfigBufferSizes(QDC_ALL_PATHS ,&NumPathArrayElements,&NumModeInfoArrayElements);
QueryDisplayConfig(QDC_ALL_PATHS ,&NumPathArrayElements, &PathInfoArray[0],&NumModeInfoArrayElements, &ModeInfoArray[0],NULL);
for(unsigned int i=0;i {
if(PathInfoArray[i].sourceInfo.id == Id)
{
PathInfoArray[i].flags=DISPLAYCONFIG_PATH_ACTIVE;
SetDisplayConfig(NumPathArrayElements, &PathInfoArray[0],NumModeInfoArrayElements, &ModeInfoArray[0],(SDC_APPLY | SDC_SAVE_TO_DATABASE| SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG));
}
Similarly trying to disable a particular secondary monitor with ID = Id by setting
PathInfoArray[i].flags = 0;
But above code is giving me inconsistent results… Sometime when I enable monitor with Id=1 , both 1 and 3rd monitors are enabled and display also gets distorted. Sometimes nothing get enabled.
Please help. Am I missing any flag here… I have tried it mannier times, but couldn’t get a single consistent behavior.
Thanks
Anshul Makkar
Having recently struggled with this api, unfortunately I have nothing to
offer except snark: consult the extensive documentation and the samples 
Obviously microsoft’s display applet knows how to do all these things
correctly. Too bad they aren’t sharing.
Mark Roddy
On Fri, Feb 1, 2013 at 12:53 PM, wrote:
> Win 7 using WDDM display driver.
>
> Trying to enable a particular secondary monitor(with ID = Id) in case of
> multiple monitors configured.
> dwStatus = GetDisplayConfigBufferSizes(QDC_ALL_PATHS
> ,&NumPathArrayElements,&NumModeInfoArrayElements);
>
> QueryDisplayConfig(QDC_ALL_PATHS ,&NumPathArrayElements,
> &PathInfoArray[0],&NumModeInfoArrayElements, &ModeInfoArray[0],NULL);
> for(unsigned int i=0;i> {
> if(PathInfoArray[i].sourceInfo.id == Id)
> {
> PathInfoArray[i].flags=DISPLAYCONFIG_PATH_ACTIVE;
> SetDisplayConfig(NumPathArrayElements,
> &PathInfoArray[0],NumModeInfoArrayElements, &ModeInfoArray[0],(SDC_APPLY |
> SDC_SAVE_TO_DATABASE| SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG));
> }
>
> Similarly trying to disable a particular secondary monitor with ID = Id by
> setting
> PathInfoArray[i].flags = 0;
>
> But above code is giving me inconsistent results… Sometime when I enable
> monitor with Id=1 , both 1 and 3rd monitors are enabled and display also
> gets distorted. Sometimes nothing get enabled.
>
> Please help. Am I missing any flag here… I have tried it mannier times,
> but couldn’t get a single consistent behavior.
>
> Thanks
> Anshul Makkar
>
> —
> NTDEV is sponsored by OSR
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
Two obvious issues stick out immediately:
- Wrong looping logic:
There is only one call to QueryDisplayConfig but many calls to SetDisplayConfig (one call per loop). The correct solution would of course only have one call to SetDisplayConfig().
- Wrong criteria for comparison:
Only “Source” is compared. This could get the same “Source” on a wrong adapter. Adapter needs to be compared, too.
The same monitor can be served by different “Sources” depending on the topology. Careful, “Source” is view index (NOT monitor index)! To identify the monitor, “Target” needs to be compared, too.
Maybe there are more mistakes, no time for further checks…
PS: It is very easy to find out what Microsoft Display Control Panel Applet is doing. Just use MS Detours (free for 32 bit OS) or one of many available open source API DLL hooks.
Marcel Ruedinger
datronicsoft
Thanks Marcel, it helped…