路径的使用:
SelectClipPath函数:
函数原型:
BOOL SelectClipPath( int nMode );
Parameters
nMode
Specifies the way to use the path. The following values are allowed:
- RGN_AND The new clipping region includes the intersection (overlapping areas) of the current clipping region and the current path. 新剪切的区域包括当前剪切区域和当前路径的一个交集!
- RGN_COPY The new clipping region is the current path.新剪切区域就是当前剪切区域
- RGN_DIFF The new clipping region includes the areas of the current clipping region, and those of the current path are excluded.新剪切区域包括当前路径区域外的当前剪切区域
- RGN_OR The new clipping region includes the union (combined areas) of the current clipping region and the current path.新剪切区域包括当前区域与当前路径的并集
- RGN_XOR The new clipping region includes the union of the current clipping region and the current path, but without the overlapping areas. 新剪切区域包括当前区域与当前路径的并集但不包括重叠区域!
RGB_AND显示效果:
RGB_DIFF显示效果:
使用代码:
CString str = "hello kity!";
CSize cs;
pDC->TextOut(30,30,str);
cs = pDC->GetTextExtent(str);
//路径的设置
pDC->BeginPath();
pDC->Rectangle(30,30,30+cs.cx,30+cs.cy);
pDC->EndPath();
pDC->SelectClipPath(RGN_AND);
str.LoadString(ID_FILE_NEW);
pDC->TextOut(0,200,str);
BeginPath:
路径的使用
与其它原有的GDI对象不同的是,MFC类库没有专门用一个C++类来封装路径对象(或许在以后的版本中会得到支持)。有关路径的定义和使用等各种操作都必须通过调用API函数(或CDC类中对应的成员函数)来实现。
BeginPath {路径开始} EndPath {路径结束}
StrokePath {绘制路径} FillPath {填充路径}
StrokeAndFillPath {绘制并填充路径}
使用代码:
RECT rect={0,0,600,200};
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // clear out structure.
lf.lfHeight = 120; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial".
CFont font;
VERIFY(font.CreatePointFontIndirect(&lf, pDC));
// Do something with the font just created...
//CFont* def_font = dc.SelectObject(&font);
CFont* pOldfont=pDC->SelectObject(&font);
pDC->BeginPath();
pDC->TextOut(400,100,"龙腾");
pDC->EndPath();
pDC->SelectObject(pOldfont);
CPen pen1(PS_SOLID,2,RGB(0,0,255));
CPen* pOldPen=pDC->SelectObject(&pen1);
//pDC->StrokePath(); //绘制路径
CBrush brush1(RGB(255,0,0));
CBrush* pOldBrush=pDC->SelectObject(&brush1);
//pDC->FillPath(); //填充路径
pDC->StrokeAndFillPath(); //绘制并填充路径
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);