MFC Support for Direct2D – Multithreading

As shown in previous articles, we can enable MFC Direct2D support for a window by a call of CWnd::EnableD2DSupport. Example: int CSlideShowWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // Enable MFC Direct2D support EnableD2DSupport(); // … return 0; } So far so good as long as all windows which use Direct2D are running … 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

Codexpert – 2015 Articles Summary

Microsoft Libraries and C++ Programming Language Using Lambdas in MFC Applications – Part 1: Sorting Arrays Presents how to sort MFC arrays using lambda expressions (C++11 and next). Using Lambdas in MFC Applications – Part 2: Replacing Callback Functions Shows examples of using lambda expressions (including nested lambdas) in MFC applications for replacing callback functions. … Read more

MFC Support for DirectWrite – Effects

We can change the color of a text range by passing a brush object to IDWriteTextLayout::SetDrawingEffect. Here is a simple example. An example of using IDWriteTextLayout::SetDrawingEffect LRESULT CDirectWriteDemoView::OnDraw2D(WPARAM wParam, LPARAM lParam) { CHwndRenderTarget* pRenderTarget = (CHwndRenderTarget*)lParam; // Please, see the demo application for more details. // … // init color effects _InitColorEffects(pRenderTarget, spTextLayout); // Draw … Read more