'Treeview Control Item hinzufügen' funktioniert nicht richtig
-
Hi,
ich nehem mal an die meisten von euch sind im Besitz der "Win32API Programers Reference".
Da ist ja ein Beispiel zum hinzufügen eines Items zu einem "Treeview Control".
Aber wenn ich da mehrere in einander verschachteln will, mit Hilfe der Variable 'nLevel', funktioniert das nicht korreckt.
kann mir jemand sagen warum?
-
Ich bin nicht im Besitz der "Win32API Programers Reference".
-----------------
tenchou ‾ω‾
-
Was meinst Du mit nLevel? Zeig uns mal Code wie Du Einträge hinzufügst. Normalerweise gibst Du einfach den Parent Knoten an und fügst einen neuen ein.
-
Das ist der Beispiel Code aus der Win32API Programers Reference
HTREEITEM AddItemToTree(HWND hwndTV, LPSTR lpszItem, int nLevel) { TV_ITEM tvi; TV_INSERTSTRUCT 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; // Set the text of the item. tvi.pszText = lpszItem; tvi.cchTextMax = lstrlen(lpszItem); // Assume the item is not a parent item, so give it a // document image. tvi.iImage = g_nDocument; tvi.iSelectedImage = g_nDocument; // Save the heading level in the item's application-defined // data area. tvi.lParam = (LPARAM) nLevel; tvins.item = tvi; tvins.hInsertAfter = hPrev; // Set the parent item based on the specified level. if (nLevel == 1) tvins.hParent = TVI_ROOT; else if (nLevel == 2) tvins.hParent = hPrevRootItem; else tvins.hParent = hPrevLev2Item; // Add the item to the tree-view control. hPrev = (HTREEITEM) SendMessage(hwndTV, TVM_INSERTITEM, 0, (LPARAM) (LPTV_INSERTSTRUCT) &tvins); // Save the handle of the item. if (nLevel == 1) hPrevRootItem = hPrev; else if (nLevel == 2) hPrevLev2Item = hPrev; // The new item is a child item. Give the parent item a // closed folder bitmap to indicate it now has child items. if (nLevel > 1) { hti = TreeView_GetParent(hwndTV, hPrev); tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.hItem = hti; tvi.iImage = g_nClosed; tvi.iSelectedImage = g_nClosed; TreeView_SetItem(hwndTV, &tvi); } return hPrev; }
-
Ich sehe hier kein Problem. Außer das dieser Stil mit den statischen Variablen eine Katastrophe ist.
-
Nagut, das ist ja auch nur ein Beispiel von Microsoft, aber ich werd`s noch mal probieren,
Danke