MFC Support for Direct2D – Transforms (1)

Direct2D supports linear transforms like translation, scale, rotation, and skew.If using MFC, we can apply transforms to render targets by calling CRenderTarget::SetTransform. Here is an example that shifts the render target 100 points on x-axis and 150 points on y-axis. It looks not very handy to fill the matrix structure, so Matrix3x2F utility class can … Read more

MFC Support for Direct2D – Lost Render Target

As stated in the Direct2D documentation, the graphics device might become unavailable. If the device is lost, the render target also becomes invalid, along with any device-dependent resources that were associated with the device. That happens infrequently (e.g. if the user removes the display adapter), but once something bad can happen, a good programmer must … Read more

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

Let’s say we have to make a slide show presentation using Cross Fade effect. If the target system is Windows 10, that’s quite easy because Direct2D offers built-in Cross Fade effect. Cross Fade effect example void CAnimationWnd::Draw(CRenderTarget* pRenderTarget) { // get ID2D1DeviceContext interface; note: must include CComQIPtr<ID2D1DeviceContext> spDeviceContext = pRenderTarget->GetRenderTarget(); // create cross-fade effect; note include … Read more

MFC Support for Direct2D – Saving to files

Once have enabled Direct2D support in an MFC application, there is no sweat to load an image from a file, by using one of CD2DBitmap constructors. Unfortunately, we cannot find a CD2DBitmap method to save it into a image file (something similar to CImage::Save or Gdiplus::Image::Save). No problem, we can try to do it ourselves. … Read more

Three Ways to Find Files

Let’ say we have to implement a function that search a folder to recursively find files having an extension from a given list of extensions. This article shows three possible implementations: one using FindFirstFile and FindNextFile WinAPI functions, one using CFileFind MFC class and one using Filesystem Library. Find files using FindFirstFile and FindNextFile WinAPI … Read more

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

Easy Screen Capture with MFC

In an older article published at Codeguru, I showed how easy is to make screen capture using CImage ATL/MFC class. Here is the sample code from that article: BOOL CScreenImage::CaptureRect(const CRect& rect) { // detach and destroy the old bitmap if any attached CImage::Destroy(); // create a screen and a memory device context HDC hDCScreen … Read more