MFC · Visual Studio
MFC Guides
Practical answers for MFC and Visual Studio. Tested code, clear steps, and real Windows screenshots.
Latest guides
Practical notes- Runtime errors
The Application Was Unable to Start Correctly (0xc000007b): Find the 32-bit/64-bit DLL Mismatch in an MFC App
An MFC app fails with 0xc000007b before its first window appears. A 64-bit EXE found a 32-bit DLL, or the reverse. Read the machine type with dumpbin, replace the DLL, and handle error 193 from LoadLibrary.
- Build errors
C4267 and C4244 in an MFC x64 Build: Fix size_t and ptrdiff_t Conversion Warnings
Rebuild a 32-bit MFC project as x64 and warnings C4267 and C4244 appear. Why size_t, INT_PTR and pointer differences no longer fit in an int, which type to use instead, and how to check the range before a DWORD conversion.
- Debugging
OutputDebugString in MFC: Debug Messages That Still Work in a Release Build
TRACE generates no code in an MFC Release build, arguments included. Send messages with OutputDebugString through a small FormatV helper, read them with DebugView without Visual Studio, and see why a path with Ł or 東京 arrives with L or ?.
- Build errors
C1010 and C1853 in MFC: Fix Precompiled Header Errors After Adding a .cpp or .c File
A .cpp or .c file added to an MFC project fails with C1010, and a .c file fails with C1853 once you add pch.h. Turn off precompiled headers for that one file instead of editing code you did not write.
- GDI
BitBlt vs StretchBlt in MFC: Shrink an Image Without Losing Lines Using HALFTONE
BitBlt copies a bitmap at its own size; StretchBlt scales it, and the destination DC's stretch mode decides the result. Why a shrunk page loses table lines or turns text into blobs, and how SetStretchBltMode(HALFTONE) with SetBrushOrgEx fixes it.
- Dialogs
OnCtlColor in MFC: Change the Background and Text Color of Edit and Static Controls
Handle WM_CTLCOLOR with OnCtlColor to color an MFC edit box or static text: keep the brush as a member, match SetBkColor to the brush, check read-only edits as CTLCOLOR_STATIC, and repaint with Invalidate.
- GDI
Capture the Screen or a Window in MFC with BitBlt: Invisible Borders, CAPTUREBLT, and PrintWindow
Copy the screen DC into a memory bitmap with BitBlt to capture a window in MFC. Why GetWindowRect adds a strip of background, how DWMWA_EXTENDED_FRAME_BOUNDS fixes it, when to use PrintWindow, and how to save the result as PNG.
- GDI
Draw a Semi-Transparent Bitmap in MFC with AlphaBlend
Use CDC::AlphaBlend to fade a whole bitmap with SourceConstantAlpha, or blend a round, soft-edged image with a premultiplied 32-bit DIB and AC_SRC_ALPHA. Why edges turn purple and GDI text disappears.
- Build errors
LNK2001 Unresolved External Symbol in MFC: Find the Missing Definition When No Caller Is Shown
LNK2001 names the missing symbol but not the function that uses it. Use the .obj at the start of the line and the shape of the name (static, virtual, GetMessageMap) to find the definition you forgot in an MFC project.
- Custom draw
Change CListCtrl Row and Cell Colors in MFC with NM_CUSTOMDRAW
OnCtlColor cannot color individual CListCtrl rows. Handle NM_CUSTOMDRAW to color a whole row or a single cell, reset the other cells, and keep the selection highlight.