自画内容的Clistctrl子类,OnCustomDraw中为什么没出现dwDrawStage=CDDS_ITEMPREPAINT | CDDS_SUBITEM的情况?
代码如下:
BOOL CGridCtrl::OnCustomDraw(IN NMHDR* Header, OUT LRESULT* Result)
{
mDraw.cd = reinterpret_cast<NMLVCUSTOMDRAW*>(Header);
switch(mDraw.cd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
{
跟踪时有进入
}
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
{
跟踪时没有进入
};
}
}
// 自画代码
void CGridCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// lpDrawItemStruct->itemState = ;
TCHAR lpBuffer[256];
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT;
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left ;
}
// Get the text
::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_WINDOW)) ;
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ;
}
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
UINT uFormat = DT_LEFT ;
::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&lpDrawItemStruct->rcItem, uFormat) ;
pDC->SelectStockObject(SYSTEM_FONT) ;
}
}