Different icons for the TreeView elements

Hello world!
I have this TreeView created and I am trying to do some special with it. Instead of the typical "folder, document" icons I want to assign more icons to its elements, depending on the element type, specified in the element structure. For example, I want a folder icon for the root element, a book icon or a web page icon for its child and a document icon or image icon for the second level elements. If it is a book or a web page, a document or a image icon depends on a value that I send for each element of the TreeView control.
So, I have this function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
HTREEITEM AddItemToTree(HWND parent, LPTSTR lpszItem, int level, bool type) {
    TVITEM tvi;
    TVINSERTSTRUCT tvins;
    static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST;
    static HTREEITEM hPrevRootItem = NULL;
    static HTREEITEM hPrevLev2Item = NULL;
    HTREEITEM hti;

    tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
    tvi.pszText = lpszItem;
    tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);

    switch (type) {
        case 0:
            tvi.iImage = bit_folder_col;
            tvi.iSelectedImage = bit_folder_exp;
        break;
        case 1:
            tvi.iImage = bit_book_col;
            tvi.iSelectedImage = bit_book_exp;
        break;
        case 2:
            tvi.iImage = bit_web_col;
            tvi.iSelectedImage = bit_web_exp;
        break;
        case 3:
            tvi.iImage = bit_cat_col;
            tvi.iSelectedImage = bit_cat_exp;
        break;
        case 4:
            tvi.iImage = bit_doc_col;
            tvi.iSelectedImage = bit_doc_exp;
        break;
        case 5:
            tvi.iImage = bit_img_col;
            tvi.iSelectedImage = bit_img_exp;
        break;
    }

    tvi.lParam = (LPARAM)level;
    tvins.item = tvi;
    tvins.hInsertAfter = hPrev;

    if (level == 1) {
        tvins.hParent = TVI_ROOT;
    } else if (level == 2) {
        tvins.hParent = hPrevRootItem;
    } else {
        tvins.hParent = hPrevLev2Item;
    }

    hPrev = (HTREEITEM)SendMessage(parent, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
    if (hPrev == NULL) return NULL;

    if (level == 1) {
        hPrevRootItem = hPrev;
    } else if (level == 2) {
        hPrevLev2Item = hPrev;
    }

    return hPrev;
}


As you see, the level argument specifies what icon must be shown for the element. The bitmaps are created (I tested it) but only the root elements icons are shown. The first and second elements take the icon of last root element created. I feel like I don't understand the way of doing this. Little help please! Thanks!
Why does this happen to me? As soon as I post my question here I find the solution of my problem.
Obviously, my problem is that "type" is a bool and can only hold 0 and 1. The curious thing is that if I send an integer value to a Boolean argument I don't get an error. The values bigger than 1 are converted to zeros.
Anything that isn't 0 is true and anything that is 0 is false. (as far as I know most compilers make this distinction implicitly)
Topic archived. No new replies allowed.