CListCtrl 中的 DrawItem 要重画数据该怎么做?
CListCtrl 中的 DrawItem 要重画数据该怎么做?
[解决办法]
- C/C++ code
LV_COLUMN lvc; ::ZeroMemory(&lvc, sizeof(lvc)); lvc.mask = LVCF_WIDTH | LVCF_FMT; int nCol = 0; for (nCol = 0; GetColumn(nCol, &lvc); nCol++) { CRect rcText; GetSubItemRect(lpDrawItemStruct->itemID, nCol, LVIR_LABEL, rcText); ::ZeroMemory(&lvi, sizeof(lvi)); lvi.iItem = lpDrawItemStruct->itemID; lvi.mask = LVIF_TEXT; lvi.iSubItem = nCol; lvi.pszText = lpBuffer; lvi.cchTextMax = sizeof(lpBuffer); VERIFY(GetItem(&lvi)); pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); UINT uFormat = DT_LEFT ; switch(lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_RIGHT: uFormat=DT_RIGHT; break; case LVCFMT_CENTER: uFormat=DT_CENTER; break; default: break; } ::DrawText(lpDrawItemStruct->hDC, lpBuffer, ::lstrlen(lpBuffer), &rcText, uFormat | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_EXTERNALLEADING) ; }
[解决办法]
CListCtrl 的重绘用OnNMCustomDraw比较方便。