Codexpert – 2017 Articles Summary

MFC Support for Direct2D – Part 3: Multithreading MFC Support for DirectWrite – Part 8: Trimming MFC Support for DirectWrite – Part 9: Hit-Test MFC Support for DirectWrite – Part 10: Outlined Text MFC Support for Direct2D – Part 4: Built-in Effects MFC Support for Direct2D – Part 5: Interoperability with GDI Double-click in MDI … Read more

MFC Support for DirectWrite – Outlined Text

In a previous article, I showed the basics of custom text rendering with DirectWrite (see MFC Support for DirectWrite – Part 7: A Step to Custom Rendering). So far so good but it just mimics the default text rendering. Let’s now modify the overridden IDWriteTextRenderer::DrawGlyphRun in order to draw outlined text. Overridden IDWriteTextRenderer::DrawGlyphRun implementation STDMETHODIMP … Read more

MFC Support for DirectWrite – Hit-Test

DirectWrite has hit-testing support that can be useful for showing a caret, making a selection, doing some action if the user chicks in a given text range, and so on. The hit-test methods of IDWriteTextLayout interface are HitTestPoint, HitTestTextPosition and HitTestTextRange. Let me show a simple example for each one. Hit-testing a point This example calls IDWriteTextLayout::HitTestPoint … Read more

MFC Support for DirectWrite – Trimming

When using “classic” GDI functions i.e. CDC::DrawText, it’s no sweat to trim with ellipsis a single-line text when that text does not fit in the drawing rectangle width, by specifying DT_WORDBREAK flag. We cannot find a similar flag for CRenderTarget::DrawText or CRenderTarget::DrawTextLayout. However, trimming a text is also possible with DirectDraw. All we have to … Read more

Codexpert – 2016 Articles Summary

C++ Programming Language Guidelines Support Library Review: span<T> Guidelines Support Library Review: string_span<T> Microsoft Libraries Easy PNG Resource Loading with MFC – Part 1 MFC Static Control Using Direct2D and DirectWrite MFC Static Control Using Direct2D and DirectWrite (updated) MFC Support for DirectWrite – Part 7: A Step to Custom Rendering Getting Direct2D, DirectWrite and … Read more

Getting Direct2D, DirectWrite and WIC Factories in MFC

MFC library offers a series of wrapper classes over Direct2D and DirectWrite interfaces (see CRenderTarget and CD2D classes). That’s pretty cool because allows to easily load and render images and draw texts, without care too much of direct dealing with COM interfaces. However, let’s say we have to implemented something different so we need to … Read more

MFC Support for DirectWrite – A Step to Custom Rendering

The previous articles from this series show how to format the text layout using built-in DirectWrite methods. However, as said earlier, we can do more custom formatting (e.g. draw double/triple underline/strikethrough, highlight text and so on). How can be done? First, let’s note that ID2D1RenderTarget::DrawTextLayout internally calls IDWriteTextLayout::Draw which has the following prototype: HRESULT Draw( … Read more

MFC Static Control Using Direct2D and DirectWrite (updated)

I have update the MFC static control presented in the previous articles by adding methods for setting text range color, typography and inline images. Code samples Setting text range color void CDemoDlg::_DoDemo_Effects() { m_staticDemo.Clear(); const CString strTagRed = _T(“RED”); const CString strTagGreen = _T(“GREEN”); const CString strTagBlue = _T(“BLUE”); CString strText; strText.Format(_T(“IDWriteTextLayout::SetDrawingEffect can change the … Read more