使用Windows API检测所有连接的监视器

DOF*_*ler 13 winapi

我正在使用Windows 7.当我在PC运行时插入新显示器时,不会自动检测到显示器.我必须转到Display-> Screen Resolution并单击Detect按钮以检测具有注册表配置的监视器.

我正在寻找一种使用Windows API以编程方式执行相同操作的方法.所以我想编写一个程序,检测所有连接的监视器再现检测按钮.我尝试使用ChangeDisplaySettingEx但结果不好.有什么建议?

Eld*_*ien 5

不是真正的 WinApi 但试试这个实用程序:

C:\Windows\System32\DisplaySwitch.exe

DisplaySwitch.exe /internal - Switch to Primary only
DisplaySwitch.exe /external - Switch to Secondary only
DisplaySwitch.exe /clone - Clone desktop on both screens (Not HDCP compliant!)
DisplaySwitch.exe /extend - Extend desktop to both screens
Run Code Online (Sandbox Code Playgroud)

特别是尝试 /extend 开关,它应该在内部执行检测。


bee*_*hol 4

不是 API 解决方案,但您可以在命令行上使用 MS 的 DevCon 实用程序来扫描新硬件。

https://support.microsoft.com/en-us/kb/311272

从该页面下载它,然后从 cmd 窗口执行:

devcon.exe rescan
Run Code Online (Sandbox Code Playgroud)

您可以轻松创建 .bat 或 .cmd 文件以从链接运行此文件。