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

** 146 Reputation points
2021-03-30T19:49:48.713+00:00

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?

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C#
{count} vote

Accepted answer
  1. Strive Sun-MSFT 426 Reputation points
    2021-04-01T03:26:30.333+00:00

    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 additional answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2021-03-31T11:14:04.32+00:00

    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();  
    }  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.