//***************************************************************************** //* //* ListSetItem //* //***************************************************************************** // Changes an item in a Tree-List-Control which is used as List-Control // iRow : Is the row of the item // nCol : Is the column of the item // pText : Is the text for the item // nImage : Is the number for the icon (use TV_NOIMAGE for no icon) // nState : Is the state of the image // TVIS_BOLD = text is bolded // TVIS_UNTERLINE = text is underlined // TVIS_SELECTED = sItem is selected // TVIS_OVERLAYMASK = overlay bits for image // TVIS_STATEIMAGEMASK = image for state icons (only for column 0) // iMask : Is the mask of bits which are used in the nState parameter // TVIS_BOLD = text is bolded // TVIS_UNTERLINE = text is underlined // TVIS_SELECTED = sItem is selected // TVIS_OVERLAYMASK = overlay bits for image // TVIS_STATEIMAGEMASK = image for state icons (only for column 0) // Returns TRUE if ok or FALSE if an error occurs BOOL CTreeListCtrl::ListSetItem(int iRow, int nCol, LPCTSTR pText, int nImage, int nState, int iMask) { TV_ITEM sData; ASSERT(::IsWindow(m_hWnd)); sData.mask = TVIF_HANDLE | TVIF_SUBITEM; sData.hItem = GetItemOfRow(iRow); sData.cChildren = nCol; if(!sData.hItem) return FALSE; if(pText) { sData.mask |= TVIF_TEXT; sData.pszText = (LPTSTR)pText; sData.cchTextMax = 256; } if(nImage >= 0) { sData.mask |= TVIF_SELECTEDIMAGE | TVIF_IMAGE ; sData.iImage = nImage; sData.iSelectedImage = nImage; } if(nState >= 0) { sData.mask |= TVIF_STATE; sData.state = nState; sData.stateMask = iMask & (TVIS_BOLD | TVIS_UNTERLINE | TVIS_SELECTED); } return SetItem(&sData); }
//***************************************************************************** //* //* ListDeleteItem //* //***************************************************************************** // Deletes an item in a Tree-List-Control which is used as List-Control // iRow : Is the row of the item // Returns TRUE if the item was deleted or FALSE if an error occurs BOOL CTreeListCtrl::ListDeleteItem(int iRow) { ASSERT(::IsWindow(m_hWnd)); return DeleteItem(GetItemOfRow(iRow)); }
//***************************************************************************** //* //* ListInsertItem //* //***************************************************************************** // Inserts an item in a Tree-List-Control which is used as List-Control // iRow : Is the row of the item // pText : Is the text for the item // nImage : Is the number for the icon (use TV_NOIMAGE for no icon) // nState : Is the state of the image // TVIS_BOLD = text is bolded // TVIS_UNTERLINE = text is underlined // TVIS_SELECTED = sItem is selected // TVIS_OVERLAYMASK = overlay bits for image // TVIS_STATEIMAGEMASK = image for state icons // iMask : Is the mask of bits which are used in the nState parameter // TVIS_BOLD = text is bolded // TVIS_UNTERLINE = text is underlined // TVIS_SELECTED = sItem is selected // TVIS_OVERLAYMASK = overlay bits for image // TVIS_STATEIMAGEMASK = image for state icons // Returns the insert position of the item or -1 if an error occurs int CTreeListCtrl::ListInsertItem(int iRow,LPCTSTR pText,int nImage,int nState,int iMask) { HTREEITEM hItem; TVINSERTSTRUCT sData; ASSERT(::IsWindow(m_hWnd)); sData.item.mask = 0; if(pText) { sData.item.mask |= TVIF_TEXT; sData.item.pszText = (LPTSTR)pText; sData.item.cchTextMax = 256; } if(nImage>=0) { sData.item.mask |= TVIF_SELECTEDIMAGE|TVIF_IMAGE ; sData.item.iImage = nImage; sData.item.iSelectedImage = nImage; } if(nState>=0) { sData.item.mask |= TVIF_STATE; sData.item.state = nState; sData.item.stateMask = iMask&(TVIS_BOLD|TVIS_UNTERLINE|TVIS_SELECTED|TVIS_OVERLAYMASK|TVIS_STATEIMAGEMASK); } hItem = GetItemOfRow(iRow); if(!hItem) { sData.hInsertAfter = TVI_LAST; sData.hParent = TVI_ROOT; } else{ sData.hParent = hItem; sData.hInsertAfter = TVI_BEFORE; } hItem = InsertItem(&sData); return GetRowOfItem(hItem); }
//***************************************************************************** //* //* ListGetColor //* //***************************************************************************** // Gets the colors of an item in a Tree-List-Control which is used as List-Control // iRow : Is the row of the item // nCol : Is the column of the item // uBkColor : Is the new background color (TV_NOCOLOR for the default color) // uTextColor : Is the new background color (TV_NOCOLOR for the default color) // Returns TRUE if ok or FALSE if an error occurs BOOL CTreeListCtrl::ListGetColor(int iRow, int nCol, COLORREF &uBkColor, COLORREF &uTextColor) { HTREEITEM hItem; hItem = GetItemOfRow(iRow); if(!hItem) { uBkColor = TV_NOCOLOR; uTextColor = TV_NOCOLOR; return FALSE; } uBkColor = GetItemBkColor(hItem, nCol); uTextColor = GetItemTextColor(hItem, nCol); return TRUE; }
//***************************************************************************** //* //* ListSetColor //* //***************************************************************************** // Changes the colors of an item in a Tree-List-Control which is used as List-Control // iRow : Is the row of the item // nCol : Is the column of the item // uBkColor : Is the new background color (use TV_NOCOLOR for the default color) // uTextColor : Is the new text color (use TV_NOCOLOR for the default color) // Returns TRUE if ok or FALSE if an error occurs BOOL CTreeListCtrl::ListSetColor(int iRow,int nCol,COLORREF uBkColor,COLORREF uTextColor) { HTREEITEM hItem; ASSERT(::IsWindow(m_hWnd)); hItem = GetItemOfRow(iRow); if(!hItem)return FALSE; SetItemBkColor (hItem,nCol,uBkColor); SetItemTextColor(hItem,nCol,uTextColor); return TRUE; }
//***************************************************************************** //* //* ListGetItemText //* //***************************************************************************** // Gets the text of an item and stores it in an buffer // iRow : Row index of the item whose text is to be retrieved. // pBuffer : Is the text buffer where the text will be saved // iMax : Is the size of the text buffer in chars // nCol : Is the column of the item // Returns a pointer to the text or NULL if an error occurs BOOL CTreeListCtrl::ListGetItemText(int iRow, LPTSTR pBuffer, int iMax, int nCol) { TV_ITEM sItem; HTREEITEM hItem; ASSERT(::IsWindow(m_hWnd)); hItem = GetItemOfRow(iRow); if(!hItem || iMax <= 0) return FALSE; pBuffer[0] = 0; sItem.mask = TVIF_TEXT | TVIF_SUBITEM; sItem.hItem = hItem; sItem.pszText = pBuffer; sItem.cchTextMax = iMax; sItem.cChildren = nCol; return GetItem(&sItem); }