How to change 3rd monitor programmatically

[亡魂溺海] 提交于 2019-12-19 08:49:21

问题


When I'm using my laptop, I use 3 displays:

  1. The laptop display
  2. A second monitor (connected through VGA)
  3. A TV (connected through HDMI)

My videocard doesn't support 3 monitors, so I'm constantly switching from 2 to 3: when I'm on the computer, I use the 2nd monitor, and when I want to watch some movies, etc. I use the 3rd.

I currently have to go to Screen Resolution, select the monitor that is not in use, and choose Extend desktop to this display.

Is there a way I can automate it?

Is there any command-line tool, or any Windows API that allows doing it?

Edit:
Display Changer seems to do what I need, but the problem is that it only detects the working monitors. The 3rd monitor (which isn't currently in use) isn't detected, so I can't attach it.


回答1:


A bit of RE on DisplaySwitch.exe shows that it calls

SetDisplayConfig(0, NULL, NULL, NULL, 0x888)

to set it to Extended on my computer.

From there, a little digging around got me to the SetDisplayConfig documentation obviously and also this SO page with some example code that queries your current display state and adds the actual flags to change them if you want to do so.




回答2:


I answered a similar question with suggestion to try UltraMon or use their SDK, but you can also hit the Win32 API directly with ChangeDisplaySettingsEx. Another user, Sai, gave an reference to an example showing use of the function.



来源:https://stackoverflow.com/questions/15031687/how-to-change-3rd-monitor-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!