IDXGISurface1::GetDC method (dxgi.h)
Returns a device context (DC) that allows you to render to a Microsoft DirectX Graphics Infrastructure (DXGI) surface using Windows Graphics Device Interface (GDI).
HRESULT GetDC( BOOL Discard, HDC *phdc );
A Boolean value that specifies whether to preserve Direct3D contents in the GDI DC. TRUE directs the runtime not to preserve Direct3D contents in the GDI DC; that is, the runtime discards the Direct3D contents. FALSE guarantees that Direct3D contents are available in the GDI DC.
A pointer to an HDC handle that represents the current device context for GDI rendering.
Returns S_OK if successful; otherwise, an error code.
This method is not supported by DXGI 1.0, which shipped in Windows Vista and Windows Server 2008. DXGI 1.1 support is required, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista with Service Pack 2 (SP2) (KB 971644) and Windows Server 2008 (KB 971512).
After you use the GetDC method to retrieve a DC, you can render to the DXGI surface by using GDI.
The GetDC method readies the surface for GDI rendering and allows inter-operation between DXGI and GDI technologies.
Keep the following in mind when using this method:
- You must create the surface by using the D3D11_RESOURCE_MISC_GDI_COMPATIBLE flag for a surface or by using the DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE flag for swap chains, otherwise this method fails.
- You must release the device and call the IDXGISurface1::ReleaseDC method before you issue any new Direct3D commands.
- This method fails if an outstanding DC has already been created by this method.
- The format for the surface or swap chain must be DXGI_FORMAT_B8G8R8A8_UNORM_SRGB or DXGI_FORMAT_B8G8R8A8_UNORM.
- On GetDC, the render target in the output merger of the Direct3D pipeline is unbound from the surface. You must call the ID3D11DeviceContext::OMSetRenderTargets method on the device prior to Direct3D rendering after GDI rendering.
- Prior to resizing buffers you must release all outstanding DCs.
IDXGISwapChain* g_pSwapChain = NULL; IDXGISurface1* g_pSurface1 = NULL; ... //Setup the device and and swapchain g_pSwapChain->GetBuffer(0, __uuidof(IDXGISurface1), (void**) &g_pSurface1); g_pSurface1->GetDC( FALSE, &g_hDC ); ... //Draw on the DC using GDI ... //When finish drawing release the DC g_pSurface1->ReleaseDC( NULL );
|Minimum supported client||Windows 7 [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2008 R2 [desktop apps | UWP apps]|