void CFastGrid::DrawText(int nItem, int nSubItem, CDC *pDC, COLORREF crText, COLORREF crBkgnd, CRect& rect, CListDataEx *pXLCD) { ASSERT(pDC); ASSERT(pXLCD); GetDrawColors(nItem, nSubItem, crText, crBkgnd); pDC->FillSolidRect(&rect, crBkgnd); CString str; str = GetItemText(nItem, nSubItem); if (!str.IsEmpty()) { // get text justification HDITEM hditem; hditem.mask = HDI_FORMAT; CHeaderCtrl *m_HeaderCtrl = GetHeaderCtrl(); m_HeaderCtrl->GetItem(nSubItem, &hditem); int nFmt = hditem.fmt & HDF_JUSTIFYMASK; UINT nFormat = DT_VCENTER | DT_SINGLELINE; if (nFmt == HDF_CENTER) nFormat |= DT_CENTER; else if (nFmt == HDF_LEFT) nFormat |= DT_LEFT; else nFormat |= DT_RIGHT; CFont *pOldFont = NULL; CFont boldfont; // check if bold specified for subitem // if (pXLCD && pXLCD[nSubItem].bBold) if (pXLCD && pXLCD->bBold) { CFont *font = pDC->GetCurrentFont(); if (font) { LOGFONT lf; font->GetLogFont(&lf); lf.lfWeight = FW_BOLD; boldfont.CreateFontIndirect(&lf); pOldFont = pDC->SelectObject(&boldfont); } } pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(crText); pDC->SetBkColor(crBkgnd); pDC->DrawText(str, &rect, nFormat); if (pOldFont) pDC->SelectObject(pOldFont); } }
void CSListCtrl::DrawText(int nItem, int nSubItem, CDC *pDC, BOOL bProgressText) { CString str = GetItemText(nItem, nSubItem); if(str.IsEmpty()) { return; } CRect rcText; if(!CalcTextRect(nItem, nSubItem, rcText)) { return; } COLORREF crText = m_crWindowText, crBkgnd = m_crWindow; GetDrawColors(nItem, nSubItem, crText, crBkgnd); // get text justification UINT nFormat = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS; if(bProgressText) { nFormat |= DT_CENTER; crText = m_crWindowText; } else { HDITEM hditem; hditem.mask = HDI_FORMAT; m_HeaderCtrl.GetItem(nSubItem, &hditem); int nFmt = hditem.fmt & HDF_JUSTIFYMASK; if (nFmt & HDF_CENTER) nFormat |= DT_CENTER; else if (nFmt & HDF_RIGHT) nFormat |= DT_RIGHT; else nFormat |= DT_LEFT; } int nOldDC = pDC->SaveDC(); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(crText); pDC->SetBkColor(crBkgnd); pDC->DrawText(str, &rcText, nFormat); pDC->RestoreDC(nOldDC); }
void CSListCtrl::DrawItem(int nItem, int nSubItem, CDC* pDC) { //Color COLORREF crText = m_crWindowText; COLORREF crBkgnd = m_crWindow; GetDrawColors(nItem, nSubItem, crText, crBkgnd); //Rectangle CRect rect; GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect); //Paint background CRect rcTemp = rect; rcTemp.bottom -= 1; pDC->FillSolidRect(&rcTemp, crBkgnd); //Sub Item data CListSubItemData* pSubItemData = GetSubItemData(nItem, nSubItem); ASSERT(pSubItemData); //1. Draw Check Box if(pSubItemData->m_nCheckState != SHC_NONE_CHECK_BOX) { DrawCheckBox(nItem, nSubItem, pDC); } //2. Draw Image if(pSubItemData->m_pListImage != NULL) { DrawImage(nItem, nSubItem, pDC); } //3. Draw Text or Progress if(pSubItemData->m_pListPrgsBar != NULL) { DrawProgressBar(nItem, nSubItem, pDC); } else { DrawText(nItem, nSubItem, pDC); } }