MFC Support for Direct2D – Composite Effects

We can combine two or more images and/or effects by using the composite effect. Here is an example. Drawing shadows using Direct2D composite effects void CD2DStaticCtrl::_DrawImageWithShadow(CHwndRenderTarget* pRenderTarget) { ASSERT(pRenderTarget && pRenderTarget->IsValid()); ASSERT(m_pBitmap && m_pBitmap->IsValid()); // get ID2D1DeviceContext interface; note: must include <d2d1_1.h> CComQIPtr<ID2D1DeviceContext> spDeviceContext = pRenderTarget->GetRenderTarget(); // create shadow effect and set the input image … Read more

MFC Support for Direct2D – Interoperability with GDI

There are two ways to combine Direct2D with Windows GDI API in the same application: Drawing Direct2D content to a GDI device context Drawing GDI content to a Direct2D GDI-compatible render target Let’s see each one! Drawing Direct2D content to a GDI device context For this purpose, use ID2D1DCRenderTarget instead of ID2D1HwndRenderTarget interface. If using MFC … Read more

MFC Support for Direct2D – Built-in Effects

Direct2D has built-in support for image processing like changing brightness or contrast, blurring, creating drop shadows, and so on. Basically, we can use for this purpose the CreateEffect and DrawImage methods of ID2D1DeviceContext interface. So far, there is no MFC wrapper class for ID2D1DeviceContext but that’s not so big issue. Once having a valid ID2D1RenderTarget … 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 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 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