MFC Support for DirectWrite – Part 4: Inline Images

DirectWrite allows inserting objects in a block of text, e.g. images, as shown in the picture.

MFC Support for DirectWrite – Inline Images

MFC Support for DirectWrite (Part 4) – Inline Images

Let’s see how can be done!

Implement IDWriteInlineObject interface methods to insert inline images

Once we have created a CD2DTextLayout object, remains the following to do:

  1. Define a class for implementing IDWriteInlineObject interface, e.g. CInlineImage. We can derive it from IDWriteInlineObject then override and implement IDWriteInlineObject and IUnknown methods. However, if we already are using MFC, it’s a little bit handier to derive from CCmdTarget, then use MFC’s interface maps DECLARE_INTERFACE_MAP, BEGIN_INTERFACE_PART and so on.

    Detailed implementation can be found in the demo application attached to this article. Here is listed just an implementation example of overridden IDWriteInlineObject::Draw.
  2. Create and initialize a CInlineImage object.

  3. Pass the CInlineImage object to IDWriteTextLayout::SetInlineObject before drawing the text layout.

Demo application

Download: MFC Support for DirectWrite Demo (Part 4).zip (1254)


  • CInlineImage class implementation is intentionally left as simple as possible, for learning purpose. Of course, it can be improved, for example, by scaling images to fit the text height.
  • Pictures used in the demo application are taken from

Resources and related articles

Leave a Reply