void _cListCtrlAutoNumbering::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// LPNMHDR pNmhdr = (LPNMHDR)pNMHDR;
// TODO: 在此添加控件通知处理程序代码
if(this->m_hWnd != pNMHDR->hwndFrom)
return;
//LPNMLVCUSTOMDRAW pDraw=(LPNMLVCUSTOMDRAW)pNMHDR;
LPNMLVCUSTOMDRAW pCustomDraw = (LPNMLVCUSTOMDRAW)pNMHDR;
int nRow = (int)pCustomDraw->nmcd.dwItemSpec;
switch (pCustomDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
// Need to process this case and set pResult to CDRF_NOTIFYITEMDRAW,
// otherwise parent will never receive CDDS_ITEMPREPAINT notification. (GGH)
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
if(this->IsWindowEnabled()==1)
{
if ((pCustomDraw->nmcd.uItemState & (CDIS_FOCUS))==0
&&GetItemState(nRow, CDIS_SELECTED)) // selected
{
pCustomDraw->clrTextBk=RGB(255, 255, 255);
pCustomDraw->clrText = RGB(0, 0, 0);
}
*pResult = CDRF_NOTIFYPOSTPAINT;
return;
}
else{
*pResult = CDRF_DODEFAULT ;
return;
}
case CDDS_ITEMPOSTPAINT:
if(this->IsWindowEnabled()==1)
{
if ((pCustomDraw->nmcd.uItemState & (CDIS_FOCUS))==0
&&GetItemState(nRow, CDIS_SELECTED)) // selected
{
CRect rcText;
DWORD_PTR hItem=pCustomDraw->nmcd.dwItemSpec;
this->GetItemRect(hItem, &rcText, LVIR_BOUNDS);
rcText.DeflateRect(1,2);
CPen penBlue(PS_SOLID ,1,RGB(0, 0, 255));
CDC* pDC=CDC::FromHandle(pCustomDraw->nmcd.hdc);
CBrush* pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush* pOldBrush = pDC->SelectObject(pBrush);
CPen* pOldPen = pDC->SelectObject(&penBlue);
pDC->Rectangle(&rcText);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
}
*pResult = CDRF_SKIPDEFAULT;
return;
}
else{
*pResult = CDRF_DODEFAULT ;
return;
}
}
*pResult = 0;
}