首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

CListCtrl 中的 DrawItem 要重画数据该如何做

2012-01-13 
CListCtrl 中的 DrawItem 要重画数据该怎么做?CListCtrl 中的 DrawItem 要重画数据该怎么做?[解决办法]C/C

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比较方便。

热点排行