Matt
2005-10-14 21:58:01 UTC
I'm just now getting into explorer-style SDIs and I'm making a program on my
own time with a CTreeView on the left side. I've made a 32-bit icon using
IconXP and I'm trying to display it along with the first element (root item)
on that tree. The text of the item displays perfectly fine, but the icon does
not. The wierdest part is that if I change the size of the icon in my image
list, the size of the element changes, so it's as if there's a blank icon
there. I've even tried using built-in icons that came as the wizard made my
MFC program, but those failed the same way. Could someone take a look and see
if they know what's going on? Thanks!
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
wchar_t* pstrTemp; // assign and release memory as
needed!
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
// First, add our images to be used
CImageList imageList;
imageList.Create(12,12,ILC_COLOR32,0,20);
imageList.Add(AfxGetApp()->LoadIconW(IDI_FOLDER_OPEN));
GetTreeCtrl().SetImageList(&imageList, TVSIL_NORMAL);
// Now load the structure data
TVINSERTSTRUCT tvItem;
TVITEMEXW tvItemDetails;
tvItem.hParent = TVI_ROOT; // root-level item
tvItem.hInsertAfter = TVI_FIRST; // sort as first item in list
tvItemDetails.state = TVIS_EXPANDED | // Default to expanded
0x0000; // no state image, no overlay mask
tvItemDetails.stateMask = 0x00FF; // only set item state
pstrTemp = new wchar_t[200]; // 199 chars should be enough
ZeroMemory(pstrTemp, 200*sizeof(wchar_t)); // ensure null terminator
LoadString(AfxGetInstanceHandle(), IDS_ROOT_NAME, pstrTemp, 200);
tvItemDetails.pszText = pstrTemp;
tvItemDetails.cchTextMax = 199; // # of chars, not size
tvItemDetails.lParam = NULL;
tvItemDetails.iImage = 0;
tvItemDetails.iSelectedImage=0;
tvItemDetails.iIntegral = 1; // standard height
tvItemDetails.mask = TVIF_INTEGRAL | // valid integral param
TVIF_STATE | // valid state/statemask params
TVIF_TEXT | // valid pszText/cchTextMax params
TVIF_IMAGE | // valid image params
TVIF_SELECTEDIMAGE;
tvItem.itemex = tvItemDetails;
// Finally add it to the list, let's store the handle
m_RootHandle = GetTreeCtrl().InsertItem(&tvItem);
int a,b;
GetTreeCtrl().GetItemImage(m_RootHandle, a, b);
// Now we can free the memory we allocated
delete[] pstrTemp;
// Blank script until the user tells us otherwise -- end here.
}
own time with a CTreeView on the left side. I've made a 32-bit icon using
IconXP and I'm trying to display it along with the first element (root item)
on that tree. The text of the item displays perfectly fine, but the icon does
not. The wierdest part is that if I change the size of the icon in my image
list, the size of the element changes, so it's as if there's a blank icon
there. I've even tried using built-in icons that came as the wizard made my
MFC program, but those failed the same way. Could someone take a look and see
if they know what's going on? Thanks!
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
wchar_t* pstrTemp; // assign and release memory as
needed!
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
// First, add our images to be used
CImageList imageList;
imageList.Create(12,12,ILC_COLOR32,0,20);
imageList.Add(AfxGetApp()->LoadIconW(IDI_FOLDER_OPEN));
GetTreeCtrl().SetImageList(&imageList, TVSIL_NORMAL);
// Now load the structure data
TVINSERTSTRUCT tvItem;
TVITEMEXW tvItemDetails;
tvItem.hParent = TVI_ROOT; // root-level item
tvItem.hInsertAfter = TVI_FIRST; // sort as first item in list
tvItemDetails.state = TVIS_EXPANDED | // Default to expanded
0x0000; // no state image, no overlay mask
tvItemDetails.stateMask = 0x00FF; // only set item state
pstrTemp = new wchar_t[200]; // 199 chars should be enough
ZeroMemory(pstrTemp, 200*sizeof(wchar_t)); // ensure null terminator
LoadString(AfxGetInstanceHandle(), IDS_ROOT_NAME, pstrTemp, 200);
tvItemDetails.pszText = pstrTemp;
tvItemDetails.cchTextMax = 199; // # of chars, not size
tvItemDetails.lParam = NULL;
tvItemDetails.iImage = 0;
tvItemDetails.iSelectedImage=0;
tvItemDetails.iIntegral = 1; // standard height
tvItemDetails.mask = TVIF_INTEGRAL | // valid integral param
TVIF_STATE | // valid state/statemask params
TVIF_TEXT | // valid pszText/cchTextMax params
TVIF_IMAGE | // valid image params
TVIF_SELECTEDIMAGE;
tvItem.itemex = tvItemDetails;
// Finally add it to the list, let's store the handle
m_RootHandle = GetTreeCtrl().InsertItem(&tvItem);
int a,b;
GetTreeCtrl().GetItemImage(m_RootHandle, a, b);
// Now we can free the memory we allocated
delete[] pstrTemp;
// Blank script until the user tells us otherwise -- end here.
}