How to detect duplicated monitors as separate screens

折月煮酒 提交于 2019-12-31 01:47:09

问题


Using the answer in this question I can get the "screen" count. However, this doesn't seem to work with monitors that are set to "duplicate" (one monitor is reported instead of 2). My application prompts a user to switch from VGA to HDMI (this is on a device with both output ports), and then puts a "can you see this?" prompt on screen to verify that both video ports are working.

I am trying to detect that the switch has happened before showing the prompt, but due to the above mentioned problem the code does not see the monitor count decrement, then increment (that is how I am detecting the switch).

How can I detect the video device switch if everything is set to duplicate? The existing code works if the monitors are set to "extend". There is an internal video device that is always present as well (not trying to test this one).


回答1:


See This question and use the provided (and fixed in the answer) wrapper for QueryDisplayConfig.

change the signature of the import to have out DisplayConfigTopologyId topology as the last parameter.

Use the QueryDisplayFlags.DatabaseCurrent for the display flags, otherwise you'll get status 87 (invalid parameter)

After calling QueryDisplayFlags the topology will be Clone, Extend etc.

call the method...

var status = CCDWrapper.QueryDisplayConfig(
    CCDWrapper.QueryDisplayFlags.DatabaseCurrent,
    ref numPathArrayElements, pathInfoArray, ref numModeInfoArrayElements,
    modeInfoArray, out currentTopologyId);

In my tests numPathArrayElements always came back as the number of monitors currently In Use. If I changed it to "Show Only Screen 1", It said 1 screen, topology internal. "Show Only Screen 2" came back with 1 screen external. "Cloned" showed 2 screens.




回答2:


James Barrass' answer didn't work for me. I ended up going with the answer here: link

Here's the code:

public static int GetScreenCount()
{
    ManagementObjectSearcher searcher =
        new ManagementObjectSearcher("root\\CIMV2",
        "SELECT * FROM Win32_PnPEntity where service =\"monitor\"");

    return searcher.Get().Count;
}


来源:https://stackoverflow.com/questions/22258906/how-to-detect-duplicated-monitors-as-separate-screens

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