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.
}
AliR.
"Matt" <Ma...@discussions.microsoft.com> wrote in message
news:152F9E28-ADFC-4F41...@microsoft.com...
-- Matt
Am also facing a similar problem. Am having a listctrl and adding a
imagelist to it. But the image is noe being displayed. I am creating the app
as a MFC smart Device app.
Please ee my code below. PLease tell mewhats the mistake and why the icon is
not displayed though i get no error. As specified in this the post i tried to
initialize the imagelist in the OnInitDialog but am not able to access it in
the eventhandler. Someone help me please. Here is the code.
BOOL CMySampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
mylistobj.InsertColumn(0,L"Name",LVCFMT_LEFT,50);
mylistobj.InsertColumn(1,L"Date",LVCFMT_LEFT,50);
mylistobj.InsertColumn(2,L"Size",LVCFMT_LEFT,50);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySampleDlg::OnBnClickedButton1()
{
CImageList il;
il.Create(IDI_ICON1,20,1,CLR_NONE);
mylistobj.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
mylistobj.SetImageList(&il,LVSIL_HEADER );
static CString details[5][3]={
L"aaaaaaaaaaaaaaaaaa",L"1stAug",L"20KB",
L"bbb",L"2ndAug",L"20KB",
L"ccc",L"3rdAug",L"20KB",
L"ddd",L"4thAug",L"20KB",
L"eee",L"5thAug",L"20KB",
};
int i=0;
// TODO: Add your control notification handler code here
for(i=0;i<5;i++)
{
//mylistobj.InsertItem(&lvi);
mylistobj.InsertItem(i,(LPCTSTR)details[i][0],0);
mylistobj.SetItemText(i,1,(LPCTSTR)details[i][1]);
mylistobj.SetItemText(i,2,(LPCTSTR)details[i][2]);
}
}
When a button is clicked a displaying the items in the listview mylistobj.
Thanks in Advance.
Regards,
Radhika
Tom
"Radhika S" <Radh...@discussions.microsoft.com> wrote in message
news:39ACCC58-EC23-4D7C...@microsoft.com...