Click to See Complete Forum and Search --> : C++ Winapi - DrawIconEx


zaryk
June 20th, 2009, 10:48 PM
Recently, I forgot to backup my programs before testing vista on my machine. But, luckily for me, I had a backup that was backed up around the time I was asking how to draw text on owner drawn listview.

So, I recovered most of my uninstaller program...I had finished...but now it seems to run a lot faster than before, and doesn't use as much memory. Obviously, I redid some of the code. Though, I am having trouble with drawing the icons. It is only when I use the below that the program has a resource/memory leak, and after a while, the icons disappear. Its probably something obvious, but any ideas?


//Draw Icon
//Located in WM_DRAWITEM
//listImage is Global - HICON listImage;
//imageList is Global - HIMAGELIST imageList;

listImage = ImageList_ExtractIcon(NULL, imageList, lDraw->itemID);
DrawIconEx(lDraw->hDC, 1, 2+lRow.top, listImage,23,23,0, NULL, DI_NORMAL);
DeleteObject(listImage);


I create the imagelist here:

//WM_CREATE
for (p = 0; p < i; p++)
{
listImage = ExtractIcon(0, ReturnChar(DisplayIcon[p]), 0);
if (listImage != NULL)
{
ImageList_AddIcon(imageList, listImage);
DeleteObject(listImage);
}
else
{
listImage = ExtractIcon(0, "shell32.dll", 162);
ImageList_AddIcon(imageList, listImage);
DeleteObject(listImage);
}

stringTogether = Box[0][p] + "\r\n" + " " + Box[2][p];

li.iItem = 0;
li.pszText=ReturnChar(stringTogether);
ListView_InsertItem(GetDlgItem(hwnd, listview), &li);
ListView_SetItemText(GetDlgItem(hwnd, listview), 0, 1, ReturnChar(Box[1][p]));
}

Marc G
June 22nd, 2009, 06:25 AM
After using ExtractIcon, use DestroyIcon to destroy it, not DeleteObject.

zaryk
June 22nd, 2009, 04:07 PM
Cool, thanks.