To render with an IDWriteBitmapRenderTarget, you must implement a custom text renderer callback interface derived from the IDWriteTextRenderer interface. You must implement methods for drawing a glyph run, underline, strikethrough, inline objects, and so on. For a complete list of the methods, see the IDWriteTextRenderer reference page. Not every method must be implemented, they can just return E_NOTIMPL, and drawing will continue.

IDWriteBitmapRenderTarget::DrawGlyphRun has an optional RECT out parameter that contains the bounds of the area where the text was drawn. You can use this information to set the bounding rectangle for the device context with the SetBoundsRect function that is provided by GDI. The following code is an example implementation of the DrawGlyphRun method of a custom renderer.

The IDWriteBitmapRenderTarget interface renders to a device context (DC) in memory. You get a handle to this DC by using the IDWriteBitmapRenderTarget::GetMemoryDC method. As soon as the drawing has been performed, the memory DC of the IDWriteBitmapRenderTarget object must be copied to the destination GDI surface.

You can retrieve the bounding rectangle by using the GetBoundsRect function, then use the bounding rectangle with the BitBlt function to copy the rendered DirectWrite text from the memory DC to the GDI surface as shown in the following code.