void GPDrawShadowTextSimple( Graphics&gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ ) { Gdiplus::Font& gcfont = fontIn; Rect rcText = CRect2Rect(rcIn); StringFormat fmt; fmt.SetAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisWord); fmt.SetLineAlignment(StringAlignmentCenter); StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn; GraphicsContainer gcContainer = gc.BeginContainer(); gc.SetSmoothingMode(SmoothingModeAntiAlias); CComBSTR btrTxtIn(strTxtIn); SolidBrush textbrush(ARGB2Color(shadowBrushClrIn)); RectF rfText = Rect2RectF(rcText); if (shadowBrushClrIn != 0) { rfText.Offset(1.0, 1.0); gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush); } textbrush.SetColor(ARGB2Color(BrushClrIn)); gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush); gc.EndContainer(gcContainer); }
void CRevisionGraphWnd::DrawShadow (GraphicsDevice& graphics, const RectF& rect, Color shadowColor, NodeShape shape) { // draw the shadow RectF shadow = rect; shadow.Offset (2, 2); Pen pen (shadowColor); SolidBrush brush (shadowColor); DrawShape (graphics, shadowColor, 1, &pen, shadowColor, &brush, shadow, shape); }
//绘制文字 void CxResLibImgList::DrawItemText( int nItem, RECT& rcLabel ) { CString strLabel = GetItemText(nItem, 0); SolidBrush brushText(m_FontColor); CStringW strLabelW; strLabelW = strLabel; if ( strLabelW.IsEmpty() ) return; RectF rcLabelF((float)rcLabel.left, (float)rcLabel.top, (float)rcLabel.right - (float)rcLabel.left , (float)rcLabel.bottom - (float)rcLabel.top); int nFirstLineCharCount = 1; CStringW strLineW; RectF rcfText; PointF ptfText; while ( nFirstLineCharCount < strLabelW.GetLength() ) { strLineW = strLabelW.Mid(0, nFirstLineCharCount); m_pGraphics->MeasureString((WCHAR*)(LPCWSTR)strLabelW , nFirstLineCharCount , m_pFont , ptfText , &rcfText ); if ( (int)rcLabelF.Width < 1 + rcfText.Width ) { nFirstLineCharCount--; if ( nFirstLineCharCount < 0 ) nFirstLineCharCount = 0; break; } nFirstLineCharCount++; } if ( nFirstLineCharCount != strLabelW.GetLength() && nFirstLineCharCount > 0 ) { //第一行 RectF rcLine = rcLabelF; rcLine.Height = rcfText.Height; strLineW = strLabelW.Mid(0, nFirstLineCharCount); m_pGraphics->DrawString((LPCWSTR)strLineW , -1 , m_pFont , rcLine , &m_FontFormat , &brushText); //第2行 rcLine.Offset(0, rcLine.Height); strLineW = strLabelW.Mid(nFirstLineCharCount, strLabelW.GetLength() - nFirstLineCharCount); if ( strLineW.GetLength() > 6 ) { CStringW str = strLineW.Mid( 0, 5 ); strLineW = str + L".."; } m_pGraphics->DrawString((LPCWSTR)strLineW , -1 , m_pFont , rcLine , &m_FontFormat , &brushText); } else { m_pGraphics->DrawString((LPCWSTR)strLabelW , -1 , m_pFont , rcLabelF , &m_FontFormat , &brushText); } }