How to disable a secondary monitor (with ChangeDisplaySettingsEx)?

后端 未结 2 749
长发绾君心
长发绾君心 2021-01-12 21:01

I\'m trying to follow the instructions on MSDN given here to disable a secondary monitor.

I\'m trying to use specifically this set of functions to allow compatibilit

2条回答
  •  爱一瞬间的悲伤
    2021-01-12 21:46

    I've decided to advance into a different problem - setting a primary display - and by pure luck I've stumbled into the solution. There are 2 conditions to disable a monitor that aren't specified anywhere: 1) You can't disable the monitor dynamically - you must use CDS_UPDATEREGISTRY to write it into the registry. 2) More importantly, for some weird reason, you must first store the change in the registry (with or without CDS_NORESET, it doesn't matter), and then use again ChangeDisplaySettingsEx with NULL values to make the changes happen. This might have something to do both monitors connected to the same display device, I'm not sure...

    Anyway here is the code that worked for me:

    result = ChangeDisplaySettingsEx(devName, &deleteScreenMode,
                                            NULL,
                                             CDS_UPDATEREGISTRY | CDS_NORESET ,
                                            NULL);
    ChangeDisplaySettingsEx (NULL, NULL, NULL, NULL, NULL);
    

    Hope it'll help someone somewhere someday.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题