Applications Windows
Réduire la table des matières
Développer la table des matières
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

ID2D1RenderTarget::EndDraw method

Ends drawing operations on the render target and indicates the current error state and associated tags.


virtual HRESULT EndDraw(
  [out, optional] D2D1_TAG *tag1 = NULL,
  [out, optional] D2D1_TAG *tag2 = NULL
) = 0;


tag1 [out, optional]

Type: D2D1_TAG*

When this method returns, contains the tag for drawing operations that caused errors or 0 if there were no errors. This parameter is passed uninitialized.

tag2 [out, optional]

Type: D2D1_TAG*

When this method returns, contains the tag for drawing operations that caused errors or 0 if there were no errors. This parameter is passed uninitialized.

Return value


If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code and sets tag1 and tag2 to the tags that were active when the error occurred.


Drawing operations can only be issued between a BeginDraw and EndDraw call.

BeginDraw and EndDraw are use to indicate that a render target is in use by the Direct2D system. Different implementations of ID2D1RenderTarget might behave differently when BeginDraw is called. An ID2D1BitmapRenderTarget may be locked between BeginDraw/EndDraw calls, a DXGI surface render target might be acquired on BeginDraw and released on EndDraw, while an ID2D1HwndRenderTarget may begin batching at BeginDraw and may present on EndDraw, for example.

The BeginDraw method must be called before rendering operations can be called, though state-setting and state-retrieval operations can be performed even outside of BeginDraw/EndDraw.

After BeginDraw is called, a render target will normally build up a batch of rendering commands, but defer processing of these commands until either an internal buffer is full, the Flush method is called, or until EndDraw is called. The EndDraw method causes any batched drawing operations to complete, and then returns an HRESULT indicating the success of the operations and, optionally, the tag state of the render target at the time the error occurred. The EndDraw method always succeeds: it should not be called twice even if a previous EndDraw resulted in a failing HRESULT.

If EndDraw is called without a matched call to BeginDraw, it returns an error indicating that BeginDraw must be called before EndDraw. Calling BeginDraw twice on a render target puts the target into an error state where nothing further is drawn, and returns an appropriate HRESULT and error information when EndDraw is called.


The following example uses an ID2D1HwndRenderTarget to draw text to a window.

//  Called whenever the application needs to display the client
//  window. This method writes "Hello, World"
//  Note that this function will automatically discard device-specific
//  resources if the Direct3D device disappears during function
//  invocation, and will recreate the resources the next time it's
//  invoked.
HRESULT DemoApp::OnRender()
    HRESULT hr;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
        static const WCHAR sc_helloWorld[] = L"Hello, World!";

        // Retrieve the size of the render target.
        D2D1_SIZE_F renderTargetSize = m_pRenderTarget->GetSize();




            ARRAYSIZE(sc_helloWorld) - 1,
            D2D1::RectF(0, 0, renderTargetSize.width, renderTargetSize.height),

        hr = m_pRenderTarget->EndDraw();

        if (hr == D2DERR_RECREATE_TARGET)
            hr = S_OK;

    return hr;


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]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]







See also




© 2017 Microsoft