While doing some refactoring on sample source code presented in MFC Support for DirectWrite series, I had the idea to make a control easy to be used for rendering text. It could be a custom MFC control derived from generic CWnd class or an ActiveX but finally I chose to derive from CStatic, just for simplicity.
By short, it consist in two main classes:
- CDirect2DStatic extends MFC class CStatic, doing the following:
- enables Direct2D MFC support;
- handles AFX_WM_DRAW2D and AFX_WM_RECREATED2DRESOURCES registered messages, which are sent by the MFC framework to a window with Direct2D MFC support enabled.
- CDirectWriteStaticCtrl, derived from CDirect2DStatic, effectively implements text formatting and rendering; it has the following groups of public methods:
- operations: setting text and background brush;
- text block format: set the format for the entire text;
- text range format: set the format in a given range;
- data access.
- Implementation details can be found in the demo application, attached here for download.
- So far, it doesn’t yet implement inline images, typography and effects but these will be done in a future version along with other Direct2D/DirectWrite features.
- See the updated version.
Download: DirectWrite Static Control.zip (496)