Easiest Custom-Draw of ListView & Best OpenThemeData() Practice

Anne Wilcoxen 46 Reputation points

In order to carry out my nefarious plans I want to add tree-view +/- dotted boxes to a list-view to make it into a tree-list-view. I have this so far:
In order to draw the tree-view elements, all I need to do is move the items in the first column over to the right depending on their indentation levels and in the space to the left use DrawThemeBackground() to draw the tree-view elements.

• What is the best practice when it comes to OpenThemeData()/CloseThemeData()? Should I keep the theme data open during the whole lifetime of the control, or is it normal to open/close it with every draw?
• What is the easiest approach to drawing this? I want the list-view to draw normally, just with some marking inserted to the left of each item. If I override WM_PAINT on the list-view control I would have to manually draw everything. But if I use LVS_OWNERDRAWFIXED + WM_DRAWITEM, don’t I have almost the same problem except that it handles the locations of each item for me? I would still have to manually draw the text, selection state, focus, etc. Is there an easier way to get the control to draw itself but with the addition of the DrawThemeBackground() elements to the left in the first column, or is LVS_OWNERDRAWFIXED + WM_DRAWITEM really the easiest way?

L. Spiro

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,513 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,226 Reputation points Microsoft Vendor

    According to CloseThemeData ,

    The CloseThemeData function should be called when a window that has a visual style applied is destroyed. This function should also be called whenever a window receives a WM_THEMECHANGED message.

    It’s necessary to utilize Custom Draw for the feature. The easier way is merging List View into Tree View. Search Win32 Editable TreeView and ListView Merged as One for an example.