question

35448318 avatar image
0 Votes"
35448318 asked 35448318 commented

How do I know which monitor is connected to which graphics card? (c++ or c#)

I can use Win32_DesktopMonitor to query all monitors, and use Win32_VideoController to query all graphics cards, but how do I know which monitor is connected to which graphics card?

dotnet-csharpc++windows-api-general
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello. @35448318

I did not find such an api that can do this. This thread contains more details.


0 Votes 0 ·
35448318 avatar image 35448318 StriveSun-MSFT ·

How does Windows Settings know? Win 7, even Win XP can do this.

83413-pic.png


Using Win32_DesktopMonitor I can get ScreenWidth and ScreenHeight, but if the driver doesn't support WDDM, these two values will not exist. And even if I get the resolution, I can't get more information like Win10 Settings.

83359-settings.png


0 Votes 0 ·
pic.png (83.2 KiB)
settings.png (26.3 KiB)
StriveSun-MSFT avatar image
0 Votes"
StriveSun-MSFT answered 35448318 commented

How could I know that Dell is connected to Display1 and VE is connected to Display2?

If you only need to know this information, you can try the EnumDisplayMonitors function.

I've posted the answer on another thread of yours. Please check it at any time.



Thank you!

If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much, this is exactly what I want.

0 Votes 0 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered 35448318 commented

Maybe you can use IDXGIAdapter
I have only 1 Monitor, so I cannot check if it works

I did this test on my OS =>

 IDXGIFactory* pdxFactory;
 HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(&pdxFactory));
 if (SUCCEEDED(hr))
 {
     int nAdapter = 0;
     while (1)
     {
         IDXGIAdapter* pdxAdapter;
         hr = pdxFactory->EnumAdapters(nAdapter, &pdxAdapter);
         if (FAILED(hr))
             break;
         else
         {
             WCHAR wsText[255] = L"";
             swprintf(wsText, L"Adapter n°%d\n", nAdapter);
             OutputDebugString(wsText);                
         }
         DXGI_ADAPTER_DESC dxAdapterDesc;
         hr = pdxAdapter->GetDesc(&dxAdapterDesc);
         if (SUCCEEDED(hr))
         {
             WCHAR wsText[255] = L"";
             swprintf(wsText, L"ID : %d - Description : %s\n", dxAdapterDesc.DeviceId, dxAdapterDesc.Description);
             OutputDebugString(wsText);
         }
         int nOutput = 0;
         while (1)
         {
             IDXGIOutput* pdxOutput;
             if (FAILED(pdxAdapter->EnumOutputs(nOutput, &pdxOutput)))
                 break;
             else
             {
                 WCHAR wsText[255] = L"";
                 swprintf(wsText, L"\tOutput n°%d\n", nOutput);
                 OutputDebugString(wsText);
             }
             DXGI_OUTPUT_DESC dxOutputDesc;
             hr = pdxOutput->GetDesc(&dxOutputDesc);
             MONITORINFO mi = { sizeof(mi) };
             GetMonitorInfo(dxOutputDesc.Monitor, &mi);
             WCHAR wsText[255] = L"";
             swprintf(wsText, L"\tDeviceName : %s - rc = {%d, %d, %d, %d}\n", dxOutputDesc.DeviceName, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom);
             OutputDebugString(wsText);
                
             pdxOutput->Release();
             nOutput++;                
         }
         pdxAdapter->Release();
         nAdapter++;
     }        
     pdxFactory->Release();
 }



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Castorix31, nice to see you again, and thank you for your reply. I tested your code and got the following information.

 ID : 8644 - Description : NVIDIA GeForce GTX 1660 SUPER
     Output n°0
     DeviceName : \\.\DISPLAY1 - rc = {0, 0, 1920, 1080}

The device name is DISPLAY1, this is the same information as Win32_VideoController. Display means that this is a port of the graphics card, not a monitor. Display is Nvidia, AMD, Intel, and so on. Monitor is Dell, HP, Sony, Samsung, Asus......

Suppose I use Win32_VideoController to get two desktop resolutions, 1920*1080 and 1600*900. And I have two monitors, Dell and HP. How do I know which monitor has which resolution?

Actually I want to get the information in the picture below. How could I know that Dell is connected to Display1 and VE is connected to Display2?

83348-settings.png


0 Votes 0 ·
settings.png (26.5 KiB)