I'm trying to obtain screenshots of multiple monitors using IDirect3DDevice9::GetFrontBufferData()
and it works but I cannot figure out how I could identify which IDirect3DDevice9
corresponds to which monitor and so how its output is positioned on Windows "virtual screen".
I tried IDirect3DDevice9::GetViewport()
but it always obtains viewport coordinates which have left top coordinate set to "0,0" (and proper width and height) so it cannot be used to identify which monitor is left and which is right.
So far I found that when I call EnumDisplayMonitors()
then monitors are enumerated in the order as devices are enumerated when I call IDirect3D9::GetAdapterDisplayMode()
and this can be used. However I see not documentation saying whether any order of enumeration is guaranteed for these two functions.
Can I rely on EnumDisplayMonitors()
and IDirect3D9::GetAdapterDisplayMode()
having the same enumeration order? Is there any better way?
Mapping a Direct3D device's swapchain back to a monitor is surprisingly challenging. Legacy Direct3D has the
HMONITOR
as noted by Raymond Chen. For a while, you could useIDXGISwapChain::GetContainingOutput
but that one has been since deprecated and no longer works like it did.The 'recommended' solution these days is something like this: