参考了code project上一个例子,用下面这个函数实现了背景色
void CLayersDia::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pRESULT)
{
// reinterpret_cast强制转换指针类型
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below.
*pRESULT = CDRF_DODEFAULT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pRESULT = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pRESULT = CDRF_NOTIFYSUBITEMDRAW;
}
else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{//这里改变背景色
COLORREF clrBkgnd;
int nCount = pLayersInfo->GetLayersCount();
int nItem = static_cast<int>(pLVCD->nmcd.dwItemSpec);
if ( 3 == pLVCD->iSubItem )
{
if(0 <= nItem && nItem < nCount)
clrBkgnd = 指定颜色;
}
// Store the colors back in the NMLVCUSTOMDRAW struct.
pLVCD->clrTextBk = clrBkgnd;
// Tell Windows to paint the control itself.
*pRESULT = CDRF_DODEFAULT;
}
}
但是我想运行时点击这一列,在弹出的对话框里选择颜色动态的修改,用了
RedrawItems()这个函数但是没有反应,不知道为什么,有什么方法可以实现动态改变背景色呢?
上次问这个问题时斑竹提到owner draw fix 属性的方法,能不能具体说一下,因为旋转这个属性后使用上面那个函数就会出错。