Did you see
this[
^] page at MSDN?
When your code is called, (via a NM_CUSTOMDRAW message) you can determine that the handler has been called for a listview or a tree-view then treat the data pointed to by lParam in the appropriate way .
In the case of a listview, the data is a NMLVCUSTOMDRAW struct, the first member of which NMCUSTOMDRAW struct. Inside this NMCUSTOMDRAW struct is a member called dwItemSpec. This contains your item number.