How to detect duplicate monitors as separate screens

Using the answer in this question, I can get a “screen” score. However, this does not seem to work with monitors that are configured for "duplication" (one monitor is displayed instead of 2). My application prompts the user to switch from VGA to HDMI (this is on a device with both output ports), and then puts "Do you see this?". on the screen to make sure that both video portals are working.

I am trying to detect that the switch occurred before showing a hint, but due to the aforementioned problem, the code does not see the decrement of the monitor counter and then increments (this is how I detect the switch).

How can I detect a video device switch if everything is set up for duplication? Existing code works if "extension" is installed for monitors. There is also an internal video device that is always present (without trying to verify this).

+4
source share
2 answers

See this question and use the provided (and corrected in response) shell for QueryDisplayConfig.

change the import signature to have out DisplayConfigTopologyId topologyas the last parameter.

Use QueryDisplayFlags.DatabaseCurrentfor display flags, otherwise you will get the status 87 (invalid parameter)

After calling QueryDisplayFlags, the topology will be Clone, Extendetc.

...

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

numPathArrayElements , . " 1", 1 , . " 2" 1 . "Cloned" 2 .

+2

. :

:

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

    return searcher.Get().Count;
}
+1

Source: https://habr.com/ru/post/1530659/


All Articles