|
-
January 15th, 2021, 01:51 PM
#9
Re: MFC CListCtrl change checkbox color
 Originally Posted by VictorN
Hi, VictorN!!! First of all i want to thank you very much for your time and help. Finally i found the almost what i need in this link: https://www.codeproject.com/Articles...n-List-Control
There is a sample of how to draw a checkbox in CHeaderCtrl using a .bmp images.
Here is some code:
BOOL CCheckListCtrl::Init()
{
if (m_blInited)
return TRUE;
CHeaderCtrl* pHeadCtrl = this->GetHeaderCtrl();
ASSERT(pHeadCtrl->GetSafeHwnd());
VERIFY( m_checkHeadCtrl.SubclassWindow(pHeadCtrl->GetSafeHwnd()) );
VERIFY( m_checkImgList.Create(IDB_CHECKBOXES, 16, 3, RGB(255,255,255)) );
int i = m_checkImgList.GetImageCount();
m_checkHeadCtrl.SetImageList(&m_checkImgList);
HDITEM hdItem;
hdItem.mask = HDI_IMAGE | HDI_FORMAT;
VERIFY( m_checkHeadCtrl.GetItem(0, &hdItem) );
hdItem.iImage = 1;
hdItem.fmt |= HDF_IMAGE;
VERIFY( m_checkHeadCtrl.SetItem(0, &hdItem) );
m_blInited = TRUE;
return TRUE;
}
void CCheckListCtrl::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW* pNMLV = (NMLISTVIEW*)pNMHDR;
*pResult = 0;
if ( m_blInited && LVIF_STATE == pNMLV->uChanged)
{
BOOL blAllChecked = TRUE;
int nCount = GetItemCount();
for(int nItem = 0; nItem < nCount; nItem++)
{
if ( !ListView_GetCheckState(GetSafeHwnd(), nItem) )
{
blAllChecked = FALSE;
break;
}
}
HDITEM hdItem;
hdItem.mask = HDI_IMAGE;
if (blAllChecked)
hdItem.iImage = 2;
else
hdItem.iImage = 1;
VERIFY( m_checkHeadCtrl.SetItem(0, &hdItem) );
}
}
I change the checkbox.bmp color and it looks like i need, but this code sample demonstrate a chechbox in CheaderCtrl!
Could you help me to undestand and find out how to do the same for CListCtrl checkboxes, i think i should use LVITEM instead of HDITEM, but i dont know how to do it and how to get the instances of checkboxes...
I am on the right way... help me please
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|