programmer2002
Programmer
Hi Gurus,
I created a dialog to display a list of icons in a list control. I got a problem that I failed to load the images into the dialog although all the items are inserted successfully. I mean that all the icons in the dialog are black. Please take a look at my code to see what the problem is inside.
Thanks all a lot.
m_pImageList = new CImageList();
m_pImageList->Create(32, 32, ILC_COLOR|ILC_COLORDDB, 0, count);
m_pImageList->SetImageCount(count);
while(...){
if(iconName.CompareNoCase(_T("") == 0 ||((iconName.Find(_T(".ico") == -1) && (iconName.Find(_T(".bmp") == -1)))
{
HICON icon = AfxGetApp()->LoadIcon(IDI_TUTICON);
m_pImageList->Add(icon);
}
else{
if(iconName.Find(_T(".ico") != -1){
HICON icon = (HICON)LoadImage(AfxGetInstanceHandle(), iconName, IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
m_pImageList->Add(icon);
}
else{
HBITMAP handle = (HBITMAP)LoadImage(AfxGetInstanceHandle(), iconName, IMAGE_BITMAP, 32, 32, LR_LOADFROMFILE);
CBitmap* bm = CBitmap::FromHandle(handle);
m_pImageList->Add(bm, RGB(0, 0, 0));
}
}
}
m_tutContainer.SetImageList(m_pImageList, LVSIL_NORMAL);
// Set the callback mask so that only the selected and focused states
// are stored for each item.
for(i = 0 ; i < count; i++){
CString strText;
strText.Format(TEXT("Tutorial %d", i+1);
// Insert the item, select every other item.
m_tutContainer.InsertItem(LVIF_IMAGE|LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, i, 0);
}
I created a dialog to display a list of icons in a list control. I got a problem that I failed to load the images into the dialog although all the items are inserted successfully. I mean that all the icons in the dialog are black. Please take a look at my code to see what the problem is inside.
Thanks all a lot.
m_pImageList = new CImageList();
m_pImageList->Create(32, 32, ILC_COLOR|ILC_COLORDDB, 0, count);
m_pImageList->SetImageCount(count);
while(...){
if(iconName.CompareNoCase(_T("") == 0 ||((iconName.Find(_T(".ico") == -1) && (iconName.Find(_T(".bmp") == -1)))
{
HICON icon = AfxGetApp()->LoadIcon(IDI_TUTICON);
m_pImageList->Add(icon);
}
else{
if(iconName.Find(_T(".ico") != -1){
HICON icon = (HICON)LoadImage(AfxGetInstanceHandle(), iconName, IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
m_pImageList->Add(icon);
}
else{
HBITMAP handle = (HBITMAP)LoadImage(AfxGetInstanceHandle(), iconName, IMAGE_BITMAP, 32, 32, LR_LOADFROMFILE);
CBitmap* bm = CBitmap::FromHandle(handle);
m_pImageList->Add(bm, RGB(0, 0, 0));
}
}
}
m_tutContainer.SetImageList(m_pImageList, LVSIL_NORMAL);
// Set the callback mask so that only the selected and focused states
// are stored for each item.
for(i = 0 ; i < count; i++){
CString strText;
strText.Format(TEXT("Tutorial %d", i+1);
// Insert the item, select every other item.
m_tutContainer.InsertItem(LVIF_IMAGE|LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, i, 0);
}