I was quite close. The full solution in pure WinAPI looks like this:
HWND mainWinHWND = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,
L"MainWindowClass",
L"WinAPI window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!mainWinHWND)
return -1;
SetWindowTheme(mainWinHWND, L"explorer", nullptr);
Then one may request OS to draw specific parts:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HTHEME theme = OpenThemeData(hwnd, L"TREEVIEW");
RECT rect;
rect.left = 10;
rect.top = 10;
rect.right = 80;
rect.bottom = 80;
DrawThemeBackground(theme, hdc, TVP_TREEITEM, TREIS_SELECTED, &rect, &rect);
CloseThemeData(theme);
EndPaint(hwnd, &ps);
return 0L;
}
Result:
It's a shame, that theming OS support is so poorly documented. For example, the L"Explorer"
value is taken from MSDN's for SetWindowTheme, but there is no official list of parameters, which may be supplied to that routine.