I'm porting over some legacy code from Dx9 to Dx11. I've managed to port over the creation of the D3D device and context fine but there's a piece of legacy code that needs to be maintained and I can't quite work out how to port it over to Dx11.
The code in question uses Win32 functions in order to get hold of a monitor's handle like so:
DEVMODE dm = { 0 };
dm.dmSize = sizeof(DEVMODE);
EnumDisplaySettings("\\\\.\\DISPLAY3", ENUM_CURRENT_SETTINGS, &dm);
POINT p = { dm.dmPosition.x, dm.dmPosition.y };
HMONITOR hMonitorGDI = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
It then loops through adapter monitors attached to a d3d9 device like so and looks for a matching handle:
unsigned int uiAdapterCount = m_p_d3d9->GetAdapterCount();
for (unsigned int i = 0; i < uiAdapterCount; ++i) {
HMONITOR hMonitorD3D = m_p_d3d9->GetAdapterMonitor(i);
if (hMonitorD3D == hMonitorGDI)
{
p_is->uiAdapter = i;
break;
}
}
I can't for the love of me work out how to do the equivalent in Dx11. I've learned how to create a DXGIFactory and through that get adapter and output (monitor) information but I can't seem to find anything with regards to retrieving a monitor's handle in Dx11.
You can use IDXGIFactory::EnumAdapters
to enumerate each adapter and IDXGIAdapter::EnumOutputs
to enumerate each adapter's outputs. Then call IDXGIOutput::GetDesc
to get an DXGI_OUTPUT_DESC
structure that includes a HMONITOR
handle for the output.
You might be able to skip a step or two in your GDI example code by looking for an output with the same desktop coordinates or perhaps device name.