Question

I'm trying to draw themed text on the window. However, instead of themed font, I always get something like bold MS Sans Serif w/o antialiasing. Why is it so?


Edit:

After applying mentioned changes, the code looks like this:

INITCOMMONCONTROLSEX ctrl;
ctrl.dwSize = sizeof(ctrl);
ctrl.dwICC = ICC_TREEVIEW_CLASSES;
InitCommonControlsEx(&ctrl);

(...)

SetWindowTheme(mainWinHWND, L"explorer", nullptr);

(...)

case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps); 

        HTHEME theme = OpenThemeData(hwnd, L"TREEVIEW");
        RECT rect;
        rect.left = 100;
        rect.top = 100;
        rect.right = 200;
        rect.bottom = 200;
        DrawThemeText(theme,
            hdc,
            TVP_TREEITEM,
            TREIS_NORMAL,
            L"Ala ma kota",
            11,
            DT_VCENTER | DT_LEFT,
            0,
            &rect);
        CloseThemeData(theme);

        EndPaint(hwnd, &ps); 
        return 0L; 
    }

The effect is still the same.


The whole code (~100 lines): http://pastebin.com/ZheZyrWy Note, that it's only a proof-of-concept program and this is why I didn't include any error-checking. But DrawThemeText returns 0 (success).

Was it helpful?

Solution

Well, you are almost there, you are getting the Explorer theme style. Just one wrong assumption, the theme for a treeview does not prescribe a font. Quite visible in the .NET TreeView class for example, you can arbitrarily assign its Font property and you'll get the requested font. And logically obvious, you didn't specify a font size anywhere so there's no reasonable way for the theming api to guess at a properly sized font. Right now you are just getting the default font that's selected in the device context.

You have to select the font you want to use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top