Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ID2D1Factory::CreateHwndRenderTarget method

Creates an ID2D1HwndRenderTarget, a render target that renders to a window.

Syntax


HRESULT CreateHwndRenderTarget(
  const D2D1_RENDER_TARGET_PROPERTIES &renderTargetProperties,
  const D2D1_HWND_RENDER_TARGET_PROPERTIES &hwndRenderTargetProperties,
  [out]  ID2D1HwndRenderTarget **hwndRenderTarget
);

Parameters

renderTargetProperties [ref]

Type: 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 [ref]

Type: const D2D1_HWND_RENDER_TARGET_PROPERTIES

The window handle, initial size (in pixels), and present options.

hwndRenderTarget [out]

Type: 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. For the complete code, see the "Hello, World" Sample Application.


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

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Header

D2d1.h

Library

D2d1.lib

DLL

D2d1.dll

See also

ID2D1Factory
"Hello, World" Sample Application

 

 

Community Additions

Show:
© 2014 Microsoft