ID2D1Factory::CreateHwndRenderTarget(constD2D1_RENDER_TARGET_PROPERTIES&,constD2D1_HWND_RENDER_TARGET_PROPERTIES&,ID2D1HwndRenderTarget**) method (d2d1.h)
Creates an ID2D1HwndRenderTarget, a render target that renders to a window.
When you create a render target, and hardware acceleration is available, you allocate resources on the computer's GPU. By creating a render target once and retaining it as long as possible, you gain performance benefits. Your application should create render targets once and hold onto them for the life of the application or until the D2DERR_RECREATE_TARGET error is received. When you receive this error, you need to recreate the render target (and any resources it created).
Syntax
HRESULT CreateHwndRenderTarget(
const D2D1_RENDER_TARGET_PROPERTIES & renderTargetProperties,
const D2D1_HWND_RENDER_TARGET_PROPERTIES & hwndRenderTargetProperties,
ID2D1HwndRenderTarget **hwndRenderTarget
);
Parameters
renderTargetProperties
Type: [in] const D2D1_RENDER_TARGET_PROPERTIES &
The rendering mode, pixel format, remoting options, DPI information, and the minimum DirectX support required for hardware rendering. For information about supported pixel formats, see Supported Pixel Formats and Alpha Modes.
hwndRenderTargetProperties
Type: [in] const D2D1_HWND_RENDER_TARGET_PROPERTIES &
The window handle, initial size (in pixels), and present options.
hwndRenderTarget
Type: [out] ID2D1HwndRenderTarget**
When this method returns, contains the address of the pointer to the ID2D1HwndRenderTarget object created by this method.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Remarks
When you create a render target and hardware acceleration is available, you allocate resources on the computer's GPU. By creating a render target once and retaining it as long as possible, you gain performance benefits. Your application should create render targets once and hold onto them for the life of the application or until the D2DERR_RECREATE_TARGET error is received. When you receive this error, you need to recreate the render target (and any resources it created).
Examples
The following example creates an ID2D1HwndRenderTarget.
RECT rc;
GetClientRect(m_hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
// Create a Direct2D render target.
hr = m_pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(m_hwnd, size),
&m_pRenderTarget
);
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | d2d1.h |
Library | D2d1.lib |
DLL | D2d1.dll |