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 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

Easy PNG Resource Loading with MFC – Part 2

A previous article demonstrates how easy is to load images from PNG resources, by using Direct2D MFC support. I have found even an easier way: CPngImage class which extends CBitmap with methods that allow loading images from PNG format files and resources. Here is a brief example: Using CPngImage class for loading PNG resources class … Read more

Read IFD and EXIF Metadata with WIC and MFC

A graphic file can store additional information abaout image (camera model, camera manufacturer, date and time, etc). Windows Imaging Component (WIC) provides interfaces which allow dealing with image metadata. Basically, for reading metadata we need an IWICMetadataQueryReader instance to call its GetMetadataByName method. The first argument of GetMetadataByName is based in Metadata Query Language and is composed by … 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

Visual Studio 2015: How to Step into MFC Framework Code

Let’s say we have installed Visual Studio 2015 and  have started an MFC application in DEBUG mode. Now, attempting to step into an MFC Framework function, e.g. CWinApp::InitInstance, the debugger simply steps over. Having a look into Output window, we may discover a message like this: “…’C:\Windows\System32\mfc140ud.dll’. Cannot find or open the PDB file”. That’s … Read more