Search code examples
cwindowswinapidirect2ddirectwrite

Does Win32 Common Controls use Direct2D now?


I have a Direct2D app where I draw text messages with DirectWrite. It's all C++. I want to add an edit control which must support emojis and a button on the right. Does Win32 edit controls and buttons can be used in a Direct2D window and is the text button rendered with DirectWrite or with the old GDI?

Thanks you


Solution

  • No GDI-based common controls in comctl32.dll use DirectWrite to draw text (too many compatibility concerns), but many newer parts of the Windows 10 shell use DirectWrite - anything based on DUI or XAML, like the Start menu or system Settings app.

    • Per Simon Mourier's comment, I wrote an SDK sample years ago called PadWrite that demos a very basic edit control, but I can't recommend it as a serious text editor because it recreates the IDWriteTextLayout object every edit. So it's best for just a few lines or paragraphs of text, as a smarter editor would selectively update only the parts of the text that changed. This works on Windows 7, but Windows 7 itself had only basic emoji support (monochrome glyphs in Segoe UI Symbol). Not until Windows 10 (with Segoe UI Emoji) did it really become colorful.
    • The newer RichEdit is also a viable option (I forget which flags enable it).
    • I've tried to subclass the standard EDIT control to intercept WM_PAINT messages (along with Edit_GetRect, GetDCEx, DefSubclassProc), but that's brittle because the HFONT does not always match the same metrics as the corresponding IDWriteFontFace due to font fallback and metrics differences between GDI vs DWrite, meaning your drawn text may not match the glyph advances the underlying EDIT control uses.
    • WinUI should work nicely if you can take a dependency on >= Windows 10.
    • There's also the Scintilla text editor which supports a DirectWrite mode. https://www.scintilla.org/ScintillaDoc.html (set SCI_SETTECHNOLOGY = SC_TECHNOLOGY_DIRECTWRITE). This will work on >= Windows 7 (or Vista with SP2 Service Pack Platform Update).