I'm trying to draw selection/focus frame in my custom windows forms control using visual styles on Windows 7 with Aero enabled. I tried this one:
VisualStyleRenderer selectionRenderer = new VisualStyleRenderer(VisualStyleElement.ListView.Item.Selected);
selectionRenderer.DrawBackground(g, visual.ItemArea);
And this one:
VisualStyleRenderer selectionRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Item.Selected);
selectionRenderer.DrawBackground(g, visual.ItemArea);
However, both fail with information, that neither TreeView.Item.Selected, nor ListView.Item.Selected is supported in current style. But hey, Windows draws the selection in the UI's treeviews:
And listviews:
So which class and part should I use to draw the system selection rectangle?
Edit: I've tried to write the code in pure WinAPI. Here's a code fragment:
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;
}
The result looks as following: