CListCtrl
-
I have used the CListCtrl example 'LVCustomDraw' to create a list control with colored columns. This works fine until I add an imagelist (BITMAP) to the list control. My class is derived from the CListCtrl class, and I use two functions 'OnEraseBkgnd' and 'OnCustomDraw' to color the alternate columns. The list control and imagelist are defined in the dialog class header ... CListCtrlEx m_ctlList; CImageList m_cImageListNormal, m_cImageListSmall, m_cImageListState; ... and the bitmap is add in the dialog class ... // Create 256 color image lists HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1); m_cImageListNormal.Attach(hList); hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1); m_cImageListSmall.Attach(hList); // Load the large icons CBitmap cBmp; cBmp.LoadBitmap(IDB_IMAGES_NORMAL); m_cImageListNormal.Add(&cBmp, RGB(255, 0, 255)); //m_colRow1 cBmp.DeleteObject(); // Load the small icons cBmp.LoadBitmap(IDB_IMAGES_SMALL); m_cImageListSmall.Add(&cBmp, RGB(255,0,255)); // Attach them m_ctlList.SetImageList(&m_cImageListNormal, LVSIL_NORMAL); m_ctlList.SetImageList(&m_cImageListSmall, LVSIL_SMALL); ... The columns and items are then added. I assume the default color of the list control is white, and the image is transparent, but when the background is redrawn, the image is not being 'refreshed', and hence it appears to have a white background. I have noticed another example on CodeProject that has a similar result when the image is added. Thank you Steve
-
I have used the CListCtrl example 'LVCustomDraw' to create a list control with colored columns. This works fine until I add an imagelist (BITMAP) to the list control. My class is derived from the CListCtrl class, and I use two functions 'OnEraseBkgnd' and 'OnCustomDraw' to color the alternate columns. The list control and imagelist are defined in the dialog class header ... CListCtrlEx m_ctlList; CImageList m_cImageListNormal, m_cImageListSmall, m_cImageListState; ... and the bitmap is add in the dialog class ... // Create 256 color image lists HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1); m_cImageListNormal.Attach(hList); hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1); m_cImageListSmall.Attach(hList); // Load the large icons CBitmap cBmp; cBmp.LoadBitmap(IDB_IMAGES_NORMAL); m_cImageListNormal.Add(&cBmp, RGB(255, 0, 255)); //m_colRow1 cBmp.DeleteObject(); // Load the small icons cBmp.LoadBitmap(IDB_IMAGES_SMALL); m_cImageListSmall.Add(&cBmp, RGB(255,0,255)); // Attach them m_ctlList.SetImageList(&m_cImageListNormal, LVSIL_NORMAL); m_ctlList.SetImageList(&m_cImageListSmall, LVSIL_SMALL); ... The columns and items are then added. I assume the default color of the list control is white, and the image is transparent, but when the background is redrawn, the image is not being 'refreshed', and hence it appears to have a white background. I have noticed another example on CodeProject that has a similar result when the image is added. Thank you Steve
-
try calling the CImageList::SetBkColor() and then check whether the background has changed or not.
nave
-
I tried setting the background color in the OnInitDialog() function. No change ... Next I tried CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL); ASSERT ( img != NULL ); but the return value of img is NULL.
-
Steve144 wrote:
CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL);
What are you tryig to do?? To get the image list in a list control there is a function called GetImageList()...
nave
Oops - not a good bit of code ... I have inserted the following code in the OnCustomDraw() function, and there is no change in B/G color of the listview image CImageList *imgS = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_SMALL ); ASSERT ( imgS != NULL ); CImageList *imgN = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_NORMAL ); ASSERT ( imgN != NULL ); ..... case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { imgS->SetBkColor ( RGB(225, 225, 225) ); imgN->SetBkColor ( RGB(225, 225, 225) );
-
Oops - not a good bit of code ... I have inserted the following code in the OnCustomDraw() function, and there is no change in B/G color of the listview image CImageList *imgS = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_SMALL ); ASSERT ( imgS != NULL ); CImageList *imgN = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_NORMAL ); ASSERT ( imgN != NULL ); ..... case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { imgS->SetBkColor ( RGB(225, 225, 225) ); imgN->SetBkColor ( RGB(225, 225, 225) );
Steve144 wrote:
imgS->SetBkColor ( RGB(225, 225, 225) );
I think you want to change the white background of the image. But the above code will set the background of the image as white itself. Try using some other color say. imgS->SetBkColor ( RGB(255,0,0) );// Red COlOR
nave
-
Steve144 wrote:
imgS->SetBkColor ( RGB(225, 225, 225) );
I think you want to change the white background of the image. But the above code will set the background of the image as white itself. Try using some other color say. imgS->SetBkColor ( RGB(255,0,0) );// Red COlOR
nave