Click to See Complete Forum and Search --> : Display process ICONs on ClistCtrl


spacefuxx
July 3rd, 2007, 10:02 AM
Hello everyone,

i'm programing an MCF process viewer. By now, everything works fine except that the ICONS of the processes don't show up (just an empty room).

I am using the ExtractIconEx API call for getting the ICON's.

This is a screenshot on which you can see what i mean:

http://www.imagebanana.com/view/1ooamz42/processmirror.JPG

And these are the code snippets (i guess the error is in the last one) :


LVCOLUMN column;
column.mask= LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
column.fmt= LVCFMT_LEFT;
column.cx= 50;
column.pszText= "PID";
m_listctrl.InsertColumn(0, &column);

column.cx= 400;
column.pszText= "Image Path";
m_listctrl.InsertColumn(1, &column);

m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);



LVITEM item;
item.mask=LVIF_TEXT | LVIF_IMAGE;
item.iItem=0;
item.iSubItem=0;
item.pszText="1999"; // process identifier (PID)

int nitem =m_listctrl.InsertItem(&item);
m_listctrl.SetItemText(nitem, 1, "c:\\myfile.exe"); // Image Path




HICON smallicon;
ExtractIconEx("c:\\myfile.exe", 0, NULL, &smallicon, 1);

CImageList imagelst;
imagelst.Create(16, 16, ILC_COLOR, 1, 1);
int iconno = imagelst.Add(smallicon);

m_listctrl.SetImageList(&imagelst, LVSIL_SMALL);
m_listctrl.SetItem(nitem, 1, LVIF_IMAGE, NULL, iconno, 0, 0, 0, 0);
DestroyIcon(smallicon);

VladimirF
July 3rd, 2007, 03:09 PM
Looks like your imagelst is a local variable, which is destroyed when that function returns...
You need to make sure that the lifetime of that variable is enough. Probably, by making it a member of your dialog class, or your list control (if you subclass it).

spacefuxx
July 4th, 2007, 08:23 AM
yeah you are right. I made the CImageList variable a member of the main dialog clas, and now all the Icons appear :)

I'm very happy about that, thank you !

VladimirF
July 4th, 2007, 11:50 AM
You are welcome.

karthikeyankrishnan
December 28th, 2007, 11:03 AM
I was able to add the images in listview columnHeader.Text and images displayed in rightside of header.But i need to display the text and image in leftside.

LVCOLUMN col;
// Use the LVM_SETCOLUMN message to set the column's image index.

// col.mask: include LVCF_FMT | LVCF_IMAGE
col.mask = LVCF_FMT | LVCF_IMAGE | LVCF_SUBITEM;

// LVCFMT_IMAGE
col.fmt = LVCFMT_IMAGE |LVCFMT_BITMAP_ON_RIGHT ;
// The image to use from the image list.
col.iSubItem=2;
col.iImage = Order;

// Initialize the rest to zero.
col.pszText = (IntPtr)0 ;
col.cchTextMax = 0;
col.cx = 0;
//col.iSubItem = 0;
col.iOrder = 0;

please reply asap