w()函数中添加如下代码:
void CPathView::OnDraw(CDC* pDC)
{
……
// TODO: add draw code for native data here
RECT rect;
GetClientRect(&rect);
CFont* pOldFont=(CFont*)pDC->SelectObject(&m_fontKaiTi);
pDC->SetBkMode(TRANSPARENT);
//定义路径
pDC->BeginPath();{
pDC->TextOut(0,10,"龙",2);
pDC->TextOut(200,10,"腾",2);
pDC->TextOut(400,10,"虎",2);
pDC->TextOut(600,10,"跃",2); }
pDC->EndPath();
pDC->SelectObject(pOldFont);
//检取路径数据
int nCount=pDC->GetPath(NULL,NULL,0);
CPoint* points=new CPoint[nCount];
BYTE* bytes=new BYTE[nCount];
pDC->GetPath(points,bytes,nCount);
//对路径定义点按正弦曲线进行变换
int i;
for(i=0;i< nCount;i++)>/p>
points[i].y=points[i].y+(int)(80*sin(points[i].x
/300.*3.1415926)+100);
//重建一个新的路径
CPoint ptStart;
pDC->BeginPath();{
for(i=0;i< nCount;i++){>/p>
switch(bytes[i]){
//移动当前点位置
case PT_MOVETO:
pDC->MoveTo(points[i]);
ptStart=points[i];
break;
//画直线
case PT_LINETO:
pDC->LineTo(points[i]);
break;
//画贝塞尔曲线
case PT_BEZIERTO:
pDC->PolyBezierTo(points+i,3);
i=i+2;
break;
//画贝塞尔曲线并封闭图形
case PT_BEZIERTO|PT_CLOSEFIGURE:
points[i+2]=ptStart;
pDC->PolyBezierTo(points+i,3);
i=i+2;
break;
//画直线并封闭图形
case PT_LINETO|PT_CLOSEFIGURE:
pDC->LineTo(ptStart);
break;
}
}
pDC->CloseFigure();
}
pDC->EndPath();
//绘制窗口灰色背景
CBrush* pOldBrush=(CBrush*)(pDC->SelectStockObject(GRAY_BRUSH));
pDC->Rectangle(&rect);
pDC->SelectObject(pOldBrush);
//设置裁剪路径
pDC->SetPolyFillMode(WINDING);
pDC->SelectClipPath(RGN_COPY);
//用位图填充裁剪区域
CBitmap bmp;
CBitmap* pBmpOld;
bmp.LoadBitmap(IDB_BMP);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
pBmpOld=dcMem.SelectObject(&bmp);
pDC->StretchBlt(0,0,rect.right,rect.bottom,
&dcMem,0,0,600,100,SRCCOPY);
dcMem.SelectObject(pBmpOld);
dcMem.DeleteDC();
bmp.DeleteObject();
}
(4)在资源中添加文字前景位图,其ID为IDB_BMP。
(5)编译,连接,运行该应用
程序。