Returns a device context (DC) that allows you to render to a Microsoft DirectX Graphics Infrastructure (DXGI) surface using Windows Graphics Device Interface (GDI).
- Discard [in]
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.
- phdc [out]
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.
You can also call GetDC on the back buffer at index 0 of a swap chain by obtaining an IDXGISurface1 from the swap chain. The following code illustrates the process.
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 | Windows Store apps]|
Minimum supported server
|Windows Server 2008 R2 [desktop apps | Windows Store apps]|
Build date: 12/16/2013