int CSkinManager::DrawGlowText(CDCHandle hdc, LPCTSTR lpchText, int cchText, LPRECT lprc, UINT format, bool bGlow) { const int iGlowMargin = 10; CDC dcMem; dcMem.CreateCompatibleDC(hdc); CBitmap bmp; BITMAPINFO dib = { sizeof(BITMAPINFOHEADER), lprc->right - lprc->left + iGlowMargin + iGlowMargin, lprc->top - lprc->bottom, 1, 32, BI_RGB }; bmp.CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); dcMem.SelectBitmap(bmp); __DTTOPTS dto = { sizeof(__DTTOPTS) }; dto.dwFlags = _DTT_TEXTCOLOR | _DTT_COMPOSITED | (bGlow ? _DTT_GLOWSIZE : 0); dto.crText = hdc.GetTextColor(); dto.iGlowSize = 8; dcMem.SelectFont(hdc.GetCurrentFont()); RECT rcText2 = { iGlowMargin, 0, lprc->right - lprc->left + iGlowMargin, lprc->bottom - lprc->top }; int iRet = ::TuoDrawThemeTextEx(s()->GetTheme(), dcMem, 0, 0, lpchText, cchText, format, &rcText2, &dto); BLENDFUNCTION bf; bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 0xff; bf.AlphaFormat = AC_SRC_ALPHA; ::AlphaBlend(hdc, lprc->left - iGlowMargin, lprc->top, lprc->right - lprc->left + iGlowMargin + iGlowMargin, lprc->bottom - lprc->top, dcMem, 0, 0, lprc->right - lprc->left + iGlowMargin + iGlowMargin, lprc->bottom - lprc->top, bf); return iRet; }
void CToolBarPropertyPage::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (lpDrawItemStruct->CtlID == IDC_LIST_ICON) { CDCHandle dc = lpDrawItemStruct->hDC; // Save these value to restore them when done drawing. COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); // If this item is selected, set the background color // and the text color to appropriate values. Also, erase // rect by filling it with the background color. if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT)); } else dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor); #if 0 // If this item has the focus, draw a red frame around the // item's rect. if ((lpDrawItemStruct->itemAction | ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS)) { CBrush br; br.CreateSolidBrush(RGB(255, 0, 0)); dc.FrameRect(&lpDrawItemStruct->rcItem, br); } #endif IconListData* pData = (IconListData*)lpDrawItemStruct->itemData; if (pData) { CIconHandle icon = m_imgList.GetIcon(pData->nIndex); if (icon.m_hIcon) icon.DrawIconEx(dc, lpDrawItemStruct->rcItem.left + cxMargin, lpDrawItemStruct->rcItem.top + cyMargin, m_iconSize.cx, m_iconSize.cy); lpDrawItemStruct->rcItem.left += m_iconSize.cx + cxMargin + IconTextMargin; // Draw the text. dc.DrawText( pData->strText, pData->strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE | DT_VCENTER); } // Reset the background color and the text color back to their // original values. dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); } }
bool CTooltipText::RanderText(CDCHandle& dc , RECT rcRect , int iRowSpace) { int iHeight = x_GetLineHeight(dc) ; CRect rc (rcRect.left,rcRect.top,rcRect.left,rcRect.top+iHeight) ; CRect rcLine (rcRect.left,rcRect.top,rcRect.left,rcRect.top+iHeight) ; list<CItemData>::iterator it = m_ItemList.begin() ; m_LinkBlockList.clear() ; for ( ;it!=m_ItemList.end() ; it++ ) { if(TIT_RETURN == it->GetType() ) { rc.bottom += iHeight ; rcLine.OffsetRect(CPoint(0,iHeight+iRowSpace)) ; rcLine.right = rcRect.left ; } else if ( TIT_LINK == it->GetType() || TIT_TEXT == it->GetType() ) { CRect rcItem = it->GetRect(dc) ; rcLine.left = rcLine.right ; rcLine.right += rcItem.right ; rcLine.right = rcLine.right>rcRect.right ? rcRect.right : rcLine.right; COLORREF clrOld = dc.GetTextColor() ; dc.SetTextColor(it->GetColor()) ; if ( it->GetType() == TIT_LINK ) { CFont font ; font.CreateFont(13,0,0,0,it->GetBold()?FW_BOLD:FW_NORMAL,0,TRUE,0,0,0,0,0,0,_T("Tahoma")) ; HFONT hOldFont = dc.SelectFont(font) ; LINKBLOCK lb = {it->GetColor(),it->GetColorHover(),it->GetColorActive(),it->GetBold(),rcLine,it->GetId(),it->GetText()}; m_LinkBlockList.push_back(lb); dc.DrawText(it->GetText().c_str() , it->GetText().size() , &rcLine , DT_NOCLIP|DT_NOPREFIX |DT_SINGLELINE|DT_WORD_ELLIPSIS) ; dc.SelectFont(hOldFont) ; } else dc.DrawText(it->GetText().c_str() , it->GetText().size() , &rcLine , DT_NOCLIP|DT_NOPREFIX |DT_SINGLELINE|DT_WORD_ELLIPSIS) ; dc.SetTextColor(clrOld) ; } } return true ; }
void CNBTreeListView::DrawTreeItem(LPNMTVCUSTOMDRAW lptvcd, UINT iState, const RECT& rcItem) { CDCHandle dc = lptvcd->nmcd.hdc; HTREEITEM hItem = (HTREEITEM) lptvcd->nmcd.dwItemSpec; tMapItem* pVal = m_mapItems.Lookup(hItem); if( pVal == NULL ) return; // NOTE: Having an ImageList attached to the TreeView control seems // to produce some extra WM_ERASEBKGND msgs, which we can use to // optimize the painting... CImageList il = m_ctrlTree.GetImageList(TVSIL_NORMAL); // If the item had focus then draw it // NOTE: Only when images are used (see note above) // FIX-BY-PATRIA: DrawFocusRect should be done later //if( (iState & CDIS_FOCUS) != 0 && !il.IsNull() ) { // RECT rcFocus = rcItem; // rcFocus.left = 1; // dc.SetTextColor(::GetSysColor(COLOR_BTNTEXT)); // dc.DrawFocusRect(&rcFocus); //} // If it's selected, paint the selection background if( iState & CDIS_SELECTED && iState & CDIS_FOCUS) { RECT rcHigh = rcItem; dc.FillSolidRect(&rcHigh, ::GetSysColor(COLOR_HIGHLIGHT)); } else if( il.IsNull() ) { RECT rcHigh = rcItem; dc.FillSolidRect(&rcHigh, lptvcd->clrTextBk); } // Always write text with background dc.SetBkMode(OPAQUE); dc.SetBkColor(::GetSysColor((iState & CDIS_SELECTED) != 0 ? COLOR_HIGHLIGHT : COLOR_WINDOW)); // Draw all columns of the item RECT rc = rcItem; int cnt = pVal->GetSize(); for( int i = 0; i < cnt; i++ ) { LPTLVITEM pItem = (*pVal)[i]; ATLASSERT(pItem); if( i != 0 ) rc.left = m_rcColumns[i].left; rc.right = m_rcColumns[i].right; if( pItem->mask & TLVIF_IMAGE ) { ATLASSERT(!il.IsNull()); int cx, cy; il.GetIconSize(cx, cy); il.DrawEx( pItem->iImage, dc, rc.left, rc.top, MIN(cx, rc.right - rc.left), cy, CLR_NONE, CLR_NONE, ILD_TRANSPARENT); rc.left += cx; } if( pItem->mask & TLVIF_TEXT ) { rc.left += 2; COLORREF clrText = lptvcd->clrText; if( pItem->mask & TLVIF_TEXTCOLOR ) clrText = pItem->clrText; if( iState & CDIS_SELECTED ) clrText = ::GetSysColor(COLOR_HIGHLIGHTTEXT); dc.SetTextColor(clrText); CFont font; HFONT hOldFont = NULL; if( pItem->mask & TLVIF_STATE ) { LOGFONT lf; ::GetObject(m_ctrlTree.GetFont(), sizeof(LOGFONT), &lf); if( pItem->state & TLVIS_BOLD ) lf.lfWeight += FW_BOLD - FW_NORMAL; if( pItem->state & TLVIS_ITALIC ) lf.lfItalic = TRUE; if( pItem->state & TLVIS_UNDERLINE ) lf.lfUnderline = TRUE; if( pItem->state & TLVIS_STRIKEOUT ) lf.lfStrikeOut = TRUE; font.CreateFontIndirect(&lf); ATLASSERT(!font.IsNull()); hOldFont = dc.SelectFont(font); } UINT format = pItem->mask & TLVIF_FORMAT ? pItem->format : 0; if (0 == i) { CNBDevice* pDevice = (CNBDevice*) m_ctrlTree.GetItemData(hItem); if (NULL != pDevice && pDevice->GetIDString(_T('*')).GetLength() > 0) { CString strBottom = pDevice->GetIDString(m_chHidden); CRect rcTop = rc; rcTop.DeflateRect(0, 0, 0, rcTop.Height() / 2); CRect rcBottom = rc; rcBottom.top = rcTop.bottom; dc.FillSolidRect(&rc, lptvcd->clrTextBk); LOGFONT lf; CFontHandle fontHandle = dc.GetCurrentFont(); fontHandle.GetLogFont(&lf); lf.lfWeight = FW_BOLD; CFont font; font.CreateFontIndirect(&lf); ATLASSERT(!font.IsNull()); HFONT hOldFont = dc.SelectFont(font); dc.DrawText(pItem->pszText, -1, &rcTop, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format); dc.SelectFont(hOldFont); COLORREF clrText = dc.GetTextColor(); clrText = RGB( (GetRValue(clrText) + 0x40) & 0xFF, (GetGValue(clrText) + 0x40) & 0xFF, (GetBValue(clrText) + 0x40) & 0xFF); clrText = dc.SetTextColor(clrText); dc.DrawText(strBottom, -1, &rcBottom, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format); dc.SetTextColor(clrText); } else { dc.FillSolidRect(&rc, lptvcd->clrTextBk); LOGFONT lf; CFontHandle fontHandle = dc.GetCurrentFont(); fontHandle.GetLogFont(&lf); lf.lfWeight = FW_BOLD; CFont font; font.CreateFontIndirect(&lf); ATLASSERT(!font.IsNull()); HFONT hOldFont = dc.SelectFont(font); dc.DrawText(pItem->pszText, -1, &rc, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format); dc.SelectFont(hOldFont); } } else { dc.DrawText(pItem->pszText, -1, &rc, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format); } if( pItem->mask & TLVIF_STATE ) dc.SelectFont(hOldFont); } } // FIX-BY-PATRIA: DrawFocusRect should be done here if( (iState & CDIS_FOCUS) != 0 && !il.IsNull() ) { RECT rcFocus = rcItem; rcFocus.left = 1; dc.SetTextColor(::GetSysColor(COLOR_BTNTEXT)); dc.DrawFocusRect(&rcFocus); } }
void CListViewCtrlEx::_DrawNormalItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem ) { if (!pItem) return; int nItem = lpdis->itemID; CDCHandle dc; dc.Attach(lpdis->hDC); HFONT hOldFont = dc.SelectFont(m_fontDef); BOOL bSelect = FALSE ; if ((lpdis->itemAction | ODA_SELECT) && (lpdis->itemState & ODS_SELECTED)) { bSelect = TRUE ; } if ( bSelect ) dc.FillSolidRect( &lpdis->rcItem, RGB(185,219,255)); else dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg); // draw check box if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) ) _DrawCheckBox(dc, lpdis->rcItem, _super::GetCheckState(nItem), pItem->dwFlags); COLORREF oldClr = dc.GetTextColor(); for(int i=0; i<pItem->subItems.size(); ++i) { CRect rcSubItem; DWORD nMarginWidth = 0; CRect rcBounds; GetSubItemRect(nItem, i, LVIR_LABEL, &rcSubItem); nMarginWidth = LEFT_MARGIN_TEXT_COLUMN+3; if(i==0) { if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) ) { nMarginWidth+=rcSubItem.left; } else { rcSubItem.left -= 19; nMarginWidth+=5; } } #define DT_FLAGS_DRAW_TEXT (DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|DT_VCENTER) rcSubItem.left += LEFT_MARGIN_TEXT_COLUMN; rcSubItem.right -= 3; const TListSubItem &subItem = pItem->subItems[i]; if(subItem.type == SUBITEM_LINK) { dc.SelectFont(m_fontLink); dc.SetTextColor(COLOR_LIST_LINK); CRect rcProbeItem; dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT); dc.DrawText( subItem.str, -1, &rcSubItem, DT_FLAGS_DRAW_TEXT); DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth; _SetColumnNeedWidth(i,nMaxWidth); } else { if (subItem.type == SUBITEM_ICON && subItem.nImg != NULL) { dc.DrawIconEx( rcSubItem.left, rcSubItem.top + 3, (HICON)subItem.nImg, 16 , 16, 0, 0, DI_NORMAL ); rcSubItem.left = rcSubItem.left + 18; } else if (subItem.type == SUBITEM_PNG) { Gdiplus::Image* pImg = BkPngPool::Get(subItem.nImg); if (pImg) { Gdiplus::Graphics graphics(dc); SIZE size = {0, 0}; if (pImg) { size.cx = pImg->GetWidth(); size.cy = pImg->GetHeight(); } graphics.DrawImage(pImg, Gdiplus::Rect(rcSubItem.left, rcSubItem.top + 5, size.cx, size.cy)); } rcSubItem.left = rcSubItem.left + 18; } else if(subItem.type==SUBITEM_COMBO) { CDC dcTmp; dcTmp.CreateCompatibleDC(dc); HBITMAP hBmpOld = dcTmp.SelectBitmap(m_bitmapCombo); dc.BitBlt(rcSubItem.right-20, rcSubItem.top + 3, 20, 20, dcTmp, 0, 0, SRCCOPY); dcTmp.SelectBitmap(hBmpOld); dcTmp.DeleteDC(); } UINT uFormat = DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER; if (i == 3) { if (pItem->nLevel == enumLevelRisk) { rcSubItem.DeflateRect(2, 3); CPen penBorder; penBorder.CreatePen( PS_SOLID, 1, RGB(224, 0, 0) ); CBrush bshInterior; bshInterior.CreateSolidBrush( RGB(224, 0, 0) ); HPEN hOldPen = dc.SelectPen( penBorder ); HBRUSH hOldBrush = dc.SelectBrush( bshInterior ); dc.RoundRect( rcSubItem, CPoint( 3, 3 ) ); dc.SelectPen(hOldPen); dc.SelectBrush(hOldBrush); dc.SetTextColor( RGB(255, 255, 255) ); } else if (pItem->nLevel == enumLevelUnknown) { rcSubItem.DeflateRect(2, 3); CPen penBorder; penBorder.CreatePen( PS_SOLID, 1, RGB(250, 115, 5) ); CBrush bshInterior; bshInterior.CreateSolidBrush( RGB(250, 115, 5) ); HPEN hOldPen = dc.SelectPen( penBorder ); HBRUSH hOldBrush = dc.SelectBrush( bshInterior ); dc.RoundRect( rcSubItem, CPoint( 3, 3 ) ); dc.SelectPen(hOldPen); dc.SelectBrush(hOldBrush); dc.SetTextColor( RGB(255, 255, 255) ); } else dc.SetTextColor( subItem.clr ); uFormat = DT_SINGLELINE|DT_CENTER|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER; } else dc.SetTextColor( subItem.clr ); dc.DrawText( subItem.str, -1, &rcSubItem, uFormat); if (subItem.type == SUBITEM_ICON || subItem.type == SUBITEM_PNG) rcSubItem.left = rcSubItem.left - 18; CRect rcProbeItem; dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT); DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth; _SetColumnNeedWidth(i,nMaxWidth); } } CPen penx; penx.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine); HPEN penOld = dc.SelectPen(penx); dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 ); CRect rcClient; GetClientRect(rcClient); dc.LineTo( lpdis->rcItem.left + rcClient.Width(), lpdis->rcItem.bottom-1); dc.SelectPen(penOld); dc.SelectFont(hOldFont); dc.SetTextColor(oldClr); dc.Detach(); }
void CListViewCtrlEx::_DrawTitleItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem ) { ATLASSERT(pItem); if(pItem->subItems.empty()) return ; int nWinWidth=lpdis->rcItem.right-lpdis->rcItem.left; CRect rcWindows; GetWindowRect(rcWindows); if ( nWinWidth > rcWindows.Width()) nWinWidth = rcWindows.Width()-20; int nItem = lpdis->itemID; CDCHandle dc; dc.Attach(lpdis->hDC); dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg); HFONT hOldFont = dc.SelectFont(m_fontDef); COLORREF clrOld = dc.GetTextColor(); COLORREF clrDef = clrOld; // RECT rcItem = lpdis->rcItem; if( pItem->dwFlags&LISTITEM_EXPANDABLE ) { //3 + 9 + 3 if(rcItem.left>-12) { CDC dcTmp; dcTmp.CreateCompatibleDC(dc); HBITMAP hBmpOld = dcTmp.SelectBitmap(m_bitmapExpand); RECT rcMinus = _GetRectMinus(rcItem); dc.BitBlt( rcMinus.left, rcMinus.top, 9, 9, dcTmp, pItem->_isclapsed? 9:0, 0, SRCCOPY); dcTmp.SelectBitmap(hBmpOld); } } for ( int i = 0; i < pItem->subItems.size(); i++) { bool bVCenter=TRUE; const TListSubItem& subItem = pItem->subItems[i]; CRect rcItem = subItem.rcOffset; if ( i == 0 ) { rcItem = lpdis->rcItem; if(pItem->nTopMargin>=0) { rcItem.top += pItem->nTopMargin; rcItem.bottom -= 0; bVCenter=FALSE; } else { rcItem.top += 2; rcItem.bottom -= 2; } rcItem.left+= pItem->nLeftmargin; } else { if ( rcItem.left < 0 ) { rcItem.left = nWinWidth+rcItem.left; } if (rcItem.right < 0) { rcItem.right = nWinWidth+rcItem.right; } rcItem.OffsetRect( lpdis->rcItem.left, lpdis->rcItem.top); } if ( subItem.type == SUBITEM_TEXT ) { dc.SetTextColor( subItem.clr); dc.SelectFont(m_fontDef); } else if ( subItem.type == SUBITEM_LINK ) { dc.SelectFont(m_fontLink); dc.SetTextColor(COLOR_LIST_LINK); } else { dc.SetTextColor( subItem.clr); dc.SelectFont(m_fontDef); } CString strTitle = subItem.str; DWORD nFlag=DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS; if(bVCenter) nFlag|=DT_VCENTER; if (i==0&&pItem->bBold||pItem->nHeightAdd!=0) { HFONT fntOld=dc.SelectFont(BkFontPool::GetFont(pItem->bBold,FALSE,FALSE,pItem->nHeightAdd)); dc.DrawText( strTitle, -1, &rcItem, nFlag); dc.SelectFont(fntOld); } else dc.DrawText( strTitle, -1, &rcItem, nFlag); } CPen pex; pex.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine); HPEN penOld = dc.SelectPen(pex); dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 ); dc.LineTo( lpdis->rcItem.right, lpdis->rcItem.bottom-1 ); dc.SetTextColor(clrOld); dc.SelectPen(penOld); dc.SelectFont(hOldFont); dc.Detach(); }