Click to See Complete Forum and Search --> : Listview control - Please help me !!!
Charles Gamble
March 29th, 1999, 04:06 AM
Question on listview control:
In my superclassed listview control I use images in some
of the list items. These have transparent backgrounds.
However, when I select a row, the transparent background is not
selected, it is still the background colour of the control.
How can I tell the control to select the transparent
background of the control as well?
Is this ownerdrawn stuff?
Thanks,
Charles Gamble.
Dan O'Brien
March 29th, 1999, 06:49 AM
Did you specify a mask when you created the ImageList? (ILC_MASK)
Charles Gamble
March 29th, 1999, 08:20 AM
Here's the code where I create the imagelist and add it to the control:
// Create and initialize image list used with control
hImageList = ImageList_Create(16,16,ILC_COLORDDB|ILC_MASK,14,1);
hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_IMAGELIST));
// Add images to image list
ImageList_AddMasked(hImageList,hBitmap,RGB(0,255,255));
DeleteObject(hBitmap);
ImageList_SetBkColor(hImageList, CLR_NONE);
// Set image list of list view
SendMessage(LVM_SETIMAGELIST,(WPARAM)LVSIL_SMALL, (LPARAM)hImageList);
Any ideas?
Charles.
Dan O'Brien
March 29th, 1999, 01:13 PM
That looks right. The only thing I do differently is pass white (RGB(255,255,255)) to AddMasked.
Charles Gamble
March 30th, 1999, 02:43 AM
I have enclosed some more code which describes how I add two of my columns
to the listview control. I am using ATL 3.0, but the principles are the same.
LVCOLUMN colDetails;
colDetails.mask = LVCF_WIDTH;
colDetails.cx = 30;
SendMessage(LVM_INSERTCOLUMN,nColumnIndex,(LPARAM)&colDetails);
nPriorityIndex = nColumnIndex;
nColumnIndex++;
SendMessage(LVM_INSERTCOLUMN,nColumnIndex,(LPARAM)&colDetails);
nStatusIndex = nColumnIndex;
nColumnIndex++;
--------(The image list is created here, using the code I sent previously)
// Get listview header
hHeader = ListView_GetHeader(m_hWndCD);
HDITEM hd;
hd.mask = HDI_FORMAT|HDI_LPARAM|HDI_IMAGE;
hd.fmt = HDF_LEFT|HDF_IMAGE;
hd.iImage = 0;
hd.lParam = ePriority;
// Set header images and LPARAM information (used to identify columns)
SendMessage(hHeader, HDM_SETITEM, nPriorityIndex, (LPARAM)&hd);
hd.iImage = 1;
hd.lParam = eStatus;
SendMessage(hHeader, HDM_SETITEM, nStatusIndex, (LPARAM)&hd);
I have my own function which selects the listview items as I want to send
events back to the container when items are selected. Below is the selecting
part of it:
// Deselect currently selected item
lvItem.state = 0;
int i = SendMessage(LVM_SETITEMSTATE, (WPARAM)-1,
(LPARAM)&lvItem);
// Select new item
lvItem.state = LVIS_SELECTED;
i = SendMessage(LVM_SETITEMSTATE, (WPARAM)HitTestInf.iItem,
(LPARAM)&lvItem);
So my main problems are that the transparent backgrounds of images are not
being highlighted when an item is selected. Also, when an image is set in the header control, there must be an image in
the column contents or else a blank space is left.
Here is the code where I add items:
// Insert item into list
lvItem.mask = LVIF_PARAM;
lvItem.iItem = SendMessage(LVM_GETITEMCOUNT, 0, 0);
lvItem.iSubItem = 0;
lvItem.lParam = (LPARAM)ActivityDetails;
SendMessage(LVM_INSERTITEM,(WPARAM)0,(LPARAM)&lvItem);
// Add Priority information
// Assign mask to text and image here, otherwise the image
// from the column header is displayed in the row
lvItem.mask = LVIF_TEXT|LVIF_IMAGE;
lvItem.iSubItem = 0
lvItem.pszText = OLE2T(bsPriority);
lvItem.cchTextMax = _tcslen(lvItem.pszText);
SendMessage(LVM_SETITEM,(WPARAM)0,(LPARAM)&lvItem);
// Add Status information
lvItem.mask = LVIF_IMAGE;
lvItem.iSubItem = 1;
lvItem.iImage = 4
SendMessage(LVM_SETITEM,0,(LPARAM)&lvItem);
Any ideas?
Are you having these problems? If not, maybe you could send me some of your
code?
Thanks for the help anyway.
Charles.
Serge Kozlov
April 1st, 1999, 07:34 PM
If you were using OWNER_DRAWn listview ctrl you could specify ILD_TRANSPARENT flag when drawing icon image yourself:
CImageList *pImageList = listView.GetImageList(LVSIL_SMALL);
if(pImageList) {
POINT pt;
pt.x = lpDrawItem->rcItem.left;
pt.y = lpDrawItem->rcItem.top;
pImageList->Draw(&dc, lvi.iImage, pt, ILD_TRANSPARENT);
}
mohini
May 11th, 2001, 01:14 AM
check out with the ILD_TRANSPARENT style
make use of ImageList_DrawEx()function in which
u can set this style
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.