www.pudn.com > DrawTextS.rar > DropShadowEffectTextView.cpp


// DropShadowEffectTextView.cpp : CDropShadowEffectTextView 类的实现 
// 
 
#include "stdafx.h" 
#include "DropShadowEffectText.h" 
 
#include "DropShadowEffectTextDoc.h" 
#include "DropShadowEffectTextView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif 
 
 
// CDropShadowEffectTextView 
 
IMPLEMENT_DYNCREATE(CDropShadowEffectTextView, CView) 
 
BEGIN_MESSAGE_MAP(CDropShadowEffectTextView, CView) 
	// 标准打印命令 
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
// CDropShadowEffectTextView 构造/析构 
 
CDropShadowEffectTextView::CDropShadowEffectTextView() 
{ 
	// TODO: 在此处添加构造代码 
 
} 
 
CDropShadowEffectTextView::~CDropShadowEffectTextView() 
{ 
} 
 
BOOL CDropShadowEffectTextView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或 
	// 样式 
 
	return CView::PreCreateWindow(cs); 
} 
 
// CDropShadowEffectTextView 绘制 
 
void CDropShadowEffectTextView::OnDraw(CDC* pDC) 
{	 
	using namespace Gdiplus; 
	CDropShadowEffectTextDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	if (!pDoc) 
		return; 
 
	CRect ClientRect; 
	GetClientRect(&ClientRect); 
	CSize ClientSize(ClientRect.Width(),ClientRect.Height()); 
	RectF theRect(ClientRect.left,ClientRect.top,ClientRect.Width(),ClientRect.Height()); 
	PointF textPos(10, ClientSize.cy/3); 
	CStringW text("文字阴影特效"); 
	FontFamily  fontFamily(L"Times New Roman"); 
	Font        font(&fontFamily, 100, FontStyleBold, UnitPixel); 
 
 
	Graphics g(pDC->m_hDC); 
	LinearGradientBrush b(theRect,Color::Blue,Color::AliceBlue,90.0f); 
 
	g.FillRectangle(&b,theRect); 
 
 
	//Make a small bitmap 
	Bitmap bm(ClientSize.cx/4,ClientSize.cy/4,&g); 
 
	//Get a graphics object for it 
 
	Graphics* bmpg = Graphics::FromImage(&bm); 
 
	// must use an antialiased rendering hint 
 
	bmpg->SetTextRenderingHint(TextRenderingHintAntiAlias); 
 
	//this matrix zooms the text out to 1/4 size and offsets it by a little right and down 
 
	Matrix mx(0.25f,0,0,0.25f,3,3); 
 
	bmpg->SetTransform(&mx); 
 
	//The shadow is drawn 
 
	bmpg->DrawString(text,-1,&font,textPos,NULL,&SolidBrush(Color(128, 0,0,0))); 
 
 
	//The destination Graphics uses a high quality mode 
 
	g.SetInterpolationMode(InterpolationModeHighQualityBicubic); 
 
	//and draws antialiased text for accurate fitting 
 
	g.SetTextRenderingHint(TextRenderingHintAntiAlias); 
 
	//The small image is blown up to fill the main client rectangle 
 
	g.DrawImage(&bm,theRect,0,0,bm.GetWidth(),bm.GetHeight(),UnitPixel); 
 
	//finally, the text is drawn on top 
 
	g.DrawString(text,-1,&font,textPos,NULL,&SolidBrush(Color::White)); 
 
 
 
 
	// TODO: 在此处为本机数据添加绘制代码 
} 
 
 
// CDropShadowEffectTextView 打印 
 
BOOL CDropShadowEffectTextView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// 默认准备 
	return DoPreparePrinting(pInfo); 
} 
 
void CDropShadowEffectTextView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: 打印前添加额外的初始化 
} 
 
void CDropShadowEffectTextView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: 打印后添加清除过程 
} 
 
 
// CDropShadowEffectTextView 诊断 
 
#ifdef _DEBUG 
void CDropShadowEffectTextView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CDropShadowEffectTextView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CDropShadowEffectTextDoc* CDropShadowEffectTextView::GetDocument() const // 非调试版本是内联的 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDropShadowEffectTextDoc))); 
	return (CDropShadowEffectTextDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
 
// CDropShadowEffectTextView 消息处理程序