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

MFC Support for DirectWrite – Typography

Some fonts like Microsoft’s Gabriola support a number of typographic features which allow users to control how they look, e.g by enabling some fancy stylistic text rendering. With DirectWrite we can do that by passing a IDWriteTypography object to IDWriteTextLayout::SetTypography method. Set text layout typography with DirectWrite in an MFC application We have not an MFC class which … Read more

MFC Support for DirectWrite – Inline Images

DirectWrite allows inserting objects in a block of text, e.g. images, as shown in the picture. 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: Define a class for implementing IDWriteInlineObject interface, e.g. CInlineImage. We can derive it from … Read more

MFC Support for DirectWrite – Text Range Format

Once having a CD2DTextLayout object containing a formatted block of text and before drawing in the render target, we can change the formatting for particular ranges of text. For that purpose, call CD2DTextLayout::Get then directly use IDWriteTextLayout interface methods like SetFontWeight, SetUnderline, SetStrikethrough and whatever else we need and is available. An example of using … Read more

MFC Support for DirectWrite – Text Block Formatting

Beside the font attributes which can be set in the CD2DTextFormat MFC class constructor, DirectWrite supports more formatting for a block of text, e.g. text alignment, word wrapping, line spacing and so on. However, if taking a look at CD2DTextFormat documentation, we cannot find functions for doing that. Don’t worry, that’s not a problem at … Read more

MFC Support for DirectWrite – The Basics

A previous article shows how easy is to make an image viewer with MFC by enabling Direct2D support and using MFC wrappers over Direct2D interfaces. Now let’s discover MFC wrapper classes for DirectWrite. A simple example of drawing texts by using MFC DirectWrite wrapper classes Basically, must follow these steps: Enable MFC support for Direct2D. A … Read more