简单问题,关于BeginPath?

yxz_lp 2007-09-26 10:45:25
void CtestView::OnDraw(CDC* pDC)
{
CString str=TEXT("test");
pDC->BeginPath();
pDC->TextOut(50,50,str);
pDC->EndPath();
}
不能显示,我用的是vs 2005。
...全文
671 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxz_lp 2007-09-28
  • 打赏
  • 举报
回复
不说了,糊里糊涂结了吧。
yxz_lp 2007-09-27
  • 打赏
  • 举报
回复
Mackz(在相互)说到了点之上,但还心存疑惑,正如上例显示空心字的例程,它并没有调用StrokeAndFillPath/FillPath/StrokePath等函数却能够正常显示,但如果把画多边形代码注释掉,就不能显示了,why?如果说是后面调用了int nNumPts = pDC->GetPath(NULL, NULL, 0);那我就注释掉 PolyDraw(pDC, lpPoints, lpTypes, nNumPts);这一行,文字也不能显示?
菜牛 2007-09-27
  • 打赏
  • 举报
回复
上面的例子是自己获得路径中的数据来绘制,相当于一个StrokePath函数了。
yxz_lp 2007-09-26
  • 打赏
  • 举报
回复
to:lyg_zy(学无止境,宁静致远)
我知道上面函数时干嘛,我的问题是在
pDC->BeginPath();
pDC->TextOut(10, 10, _T("Hockey is Best!"));
pDC->EndPath();
之间代码没起作用。
to:xlzxlich(阳光)
你应该首先建立一个区域?我看了MSDN,没有提到你所说的要求,只有在这之间的函数调用有版本要求,还有一些书籍上也是这样直接调用。
lyg_zy 2007-09-26
  • 打赏
  • 举报
回复
你运行一下以下代码你就知道BeginPath是做什么的了。
它可以用来做空心字,艺术字等。

// This OnDraw() implementation uses GDI paths to draw the outline of
// some text in a TrueType font. The path is used to record the way
// the TrueType font would be drawn. Then, the function uses the data
// returned from CDC::GetPath() to draw the font--without filling it.

void COutlineView::OnDraw(CDC* pDC)
{
// Describe a 24-point truetype font of normal weight
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -MulDiv(24, pDC->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;

// create and select it
CFont newFont;
if (!newFont.CreateFontIndirect(&lf))
return;
CFont* pOldFont = pDC->SelectObject(&newFont);

// use a path to record how the text was drawn
pDC->BeginPath();
pDC->TextOut(10, 10, _T("Hockey is Best!"));
pDC->EndPath();

// Find out how many points are in the path. Note that
// for long strings or complex fonts, this number might be
// gigantic!
int nNumPts = pDC->GetPath(NULL, NULL, 0);
if (nNumPts == 0)
return;

// Allocate memory to hold points and stroke types from
// the path.
LPPOINT lpPoints = new POINT[nNumPts];
if (lpPoints == NULL)
return;
LPBYTE lpTypes = new BYTE[nNumPts];
if (lpTypes == NULL)
{
delete [] lpPoints;
return;
}

// Now that we have the memory, really get the path data.
nNumPts = pDC->GetPath(lpPoints, lpTypes, nNumPts);

// If it worked, draw the lines. Win95 and Win98 don't support
// the PolyDraw API, so we use our own member function to do
// similar work. If you're targeting only Windows NT, you can
// use the PolyDraw() API and avoid the COutlineView::PolyDraw()
// member function.

if (nNumPts != -1)
PolyDraw(pDC, lpPoints, lpTypes, nNumPts);

// Release the memory we used
delete [] lpPoints;
delete [] lpTypes;

// Put back the old font
pDC->SelectObject(pOldFont);

return;
}

void COutlineView::PolyDraw(CDC* pDC, CONST LPPOINT lppt, CONST LPBYTE lpbTypes,
int cCount)
{
int nIndex;
LPPOINT pptLastMoveTo = NULL;

// for each of the points we have...
for (nIndex = 0; nIndex < cCount; nIndex++)
{
switch(lpbTypes[nIndex])
{
// React to information from the path by drawing the data
// we received. For each of the points, record our own
// "last active point" so we can close figures, lines, and
// Beziers.

case PT_MOVETO:
if (pptLastMoveTo != NULL && nIndex > 0)
pDC->LineTo(pptLastMoveTo->x, pptLastMoveTo->y);
pDC->MoveTo(lppt[nIndex].x, lppt[nIndex].y);
pptLastMoveTo = &lppt[nIndex];
break;

case PT_LINETO | PT_CLOSEFIGURE:
pDC->LineTo(lppt[nIndex].x, lppt[nIndex].y);
if (pptLastMoveTo != NULL)
pDC->LineTo(pptLastMoveTo->x, pptLastMoveTo->y);
pptLastMoveTo = NULL;
break;

case PT_LINETO:
pDC->LineTo(lppt[nIndex].x, lppt[nIndex].y);
break;

case PT_BEZIERTO | PT_CLOSEFIGURE:
ASSERT(nIndex + 2 <= cCount);
pDC->PolyBezierTo(&lppt[nIndex], 3);
nIndex += 2;
if (pptLastMoveTo != NULL)
pDC->LineTo(pptLastMoveTo->x, pptLastMoveTo->y);
pptLastMoveTo = NULL;
break;

case PT_BEZIERTO:
ASSERT(nIndex + 2 <= cCount);
pDC->PolyBezierTo(&lppt[nIndex], 3);
nIndex += 2;
break;
}
}

// If the figure was never closed and should be,
// close it now.
if (pptLastMoveTo != NULL && nIndex > 1)
pDC->LineTo(pptLastMoveTo->x, pptLastMoveTo->y);
}
xlzxlich 2007-09-26
  • 打赏
  • 举报
回复
BeginPath是区域函数

你应该首先建立一个区域,然后再用BeginPath();
EndPath()进行区域图形绘制。
yxz_lp 2007-09-26
  • 打赏
  • 举报
回复
分++~~~
菜牛 2007-09-26
  • 打赏
  • 举报
回复
BeginPath/EndPath在当前DC中创建了一个路径对象,这个路径对象要绘制出来,还需要调用StrokeAndFillPath/FillPath/StrokePath等函数。
yxz_lp 2007-09-26
  • 打赏
  • 举报
回复
void CtestView::OnDraw(CDC* pDC)
{
CtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

// TODO: 在此处为本机数据添加绘制代码
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -MulDiv(24, pDC->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;

// create and select it
CFont newFont;
if (!newFont.CreateFontIndirect(&lf))
return;
CFont* pOldFont = pDC->SelectObject(&newFont);

// use a path to record how the text was drawn
pDC->BeginPath();
pDC->TextOut(10, 10, _T("Hockey is Best!"));
pDC->EndPath();

//// Find out how many points are in the path. Note that
//// for long strings or complex fonts, this number might be
//// gigantic!
//int nNumPts = pDC->GetPath(NULL, NULL, 0);
//if (nNumPts == 0)
// return;

//// Allocate memory to hold points and stroke types from
//// the path.
//LPPOINT lpPoints = new POINT[nNumPts];
//if (lpPoints == NULL)
// return;
//LPBYTE lpTypes = new BYTE[nNumPts];
//if (lpTypes == NULL)
//{
// delete [] lpPoints;
// return;
//}

//// Now that we have the memory, really get the path data.
//nNumPts = pDC->GetPath(lpPoints, lpTypes, nNumPts);

//// If it worked, draw the lines. Win95 and Win98 don't support
//// the PolyDraw API, so we use our own member function to do
//// similar work. If you're targeting only Windows NT, you can
//// use the PolyDraw() API and avoid the COutlineView::PolyDraw()
//// member function.

//if (nNumPts != -1)
// PolyDraw(pDC->GetSafeHdc(), lpPoints, lpTypes, nNumPts);

//// Release the memory we used
//delete [] lpPoints;
//delete [] lpTypes;

//// Put back the old font
pDC->SelectObject(pOldFont);

return;

}//这样还是不能显示,删除了画多边型的代码
acinonyx 2007-09-26
  • 打赏
  • 举报
回复
你直接用pDC->TextOut(50,50,str);就会出来了,呵呵
真相重于对错 2007-09-26
  • 打赏
  • 举报
回复
void COutlineView::OnDraw(CDC* pDC)
{
// Describe a 24-point truetype font of normal weight
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -MulDiv(24, pDC->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;

// create and select it
CFont newFont;
if (!newFont.CreateFontIndirect(&lf))
return;
CFont* pOldFont = pDC->SelectObject(&newFont);

// use a path to record how the text was drawn
pDC->BeginPath();
pDC->TextOut(10, 10, _T("Hockey is Best!"));
pDC->EndPath();

// Find out how many points are in the path. Note that
// for long strings or complex fonts, this number might be
// gigantic!
int nNumPts = pDC->GetPath(NULL, NULL, 0);
if (nNumPts == 0)
return;

// Allocate memory to hold points and stroke types from
// the path.
LPPOINT lpPoints = new POINT[nNumPts];
if (lpPoints == NULL)
return;
LPBYTE lpTypes = new BYTE[nNumPts];
if (lpTypes == NULL)
{
delete [] lpPoints;
return;
}

// Now that we have the memory, really get the path data.
nNumPts = pDC->GetPath(lpPoints, lpTypes, nNumPts);

// If it worked, draw the lines. Win95 and Win98 don't support
// the PolyDraw API, so we use our own member function to do
// similar work. If you're targeting only Windows NT, you can
// use the PolyDraw() API and avoid the COutlineView::PolyDraw()
// member function.

if (nNumPts != -1)
PolyDraw(pDC, lpPoints, lpTypes, nNumPts);

// Release the memory we used
delete [] lpPoints;
delete [] lpTypes;

// Put back the old font
pDC->SelectObject(pOldFont);

return;
}
真相重于对错 2007-09-26
  • 打赏
  • 举报
回复
设定字体和颜色了没
lyg_zy 2007-09-26
  • 打赏
  • 举报
回复
to lz
pDC->BeginPath();
pDC->TextOut(10, 10, _T("Hockey is Best!"));
pDC->EndPath();
这个怎么没起作用?它把dc里的当前path替换了。以后你再pDC->GetPath(...)得到的就是你是你TextOut"Hockey is Best!"文字的绘制路径呀。相当于你就可以拿到了windows绘制"Hockey is Best"文字的一系列点和绘制方式呀。





yxz_lp 2007-09-26
  • 打赏
  • 举报
回复
up

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧