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 API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,238 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
{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 81,721 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();  
    }