代码如下:
void CMyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo); pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(254, 254);
int nX = pDC->GetDeviceCaps(LOGPIXELSX);
int nY = pDC->GetDeviceCaps(LOGPIXELSY);
pDC->SetViewportExt(nX, -nY);
}void AcDbPoint::WorldDraw(CDC* pDC)
{
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Pen Pen(Color(255, GetRValue(m_nColor), GetGValue(m_nColor), GetBValue(m_nColor)));
graphics.DrawEllipse(&Pen, m_Position.GetX(), m_Position.GetY(), 4, 4); DrawErrorPoint(pDC, m_Position);
}void AcDbPoint::DrawErrorPoint(CDC* pDC, AcGePoint hotPt)
{
g_pCadView->LPtoDP(hotPt);
int nDc = pDC->SaveDC(); pDC->SetMapMode(MM_TEXT);
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Pen Pen(Color(255, GetRValue(m_nColor), GetGValue(m_nColor), GetBValue(m_nColor)));
graphics.DrawEllipse(&Pen, hotPt.GetX(), hotPt.GetY(), 8, 8);
pDC->RestoreDC(nDc);
}问题是这样的,画是可以画出的,但是刷新的时候有问题,可能是MM_TEXT造成的,如果WorldDraw中不使用GDI+绘图则不会出现刷新问题,请高手出招.
void CMyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo); pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(254, 254);
int nX = pDC->GetDeviceCaps(LOGPIXELSX);
int nY = pDC->GetDeviceCaps(LOGPIXELSY);
pDC->SetViewportExt(nX, -nY);
}void AcDbPoint::WorldDraw(CDC* pDC)
{
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Pen Pen(Color(255, GetRValue(m_nColor), GetGValue(m_nColor), GetBValue(m_nColor)));
graphics.DrawEllipse(&Pen, m_Position.GetX(), m_Position.GetY(), 4, 4); DrawErrorPoint(pDC, m_Position);
}void AcDbPoint::DrawErrorPoint(CDC* pDC, AcGePoint hotPt)
{
g_pCadView->LPtoDP(hotPt);
int nDc = pDC->SaveDC(); pDC->SetMapMode(MM_TEXT);
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Pen Pen(Color(255, GetRValue(m_nColor), GetGValue(m_nColor), GetBValue(m_nColor)));
graphics.DrawEllipse(&Pen, hotPt.GetX(), hotPt.GetY(), 8, 8);
pDC->RestoreDC(nDc);
}问题是这样的,画是可以画出的,但是刷新的时候有问题,可能是MM_TEXT造成的,如果WorldDraw中不使用GDI+绘图则不会出现刷新问题,请高手出招.
只用一个Graphics对象,而不是两个。可是我要改变CDC的映射模式.
{
{
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Pen Pen(Color(255, GetRValue(m_nColor), GetGValue(m_nColor), GetBValue(m_nColor)));
graphics.DrawEllipse(&Pen, m_Position.GetX(), m_Position.GetY(), 4, 4);
}
DrawErrorPoint(pDC, m_Position);
}
这样就行了(加了大括号),弱智问题,为什么?你还问为什么,看MSDN吧,还那么多星星呢。
你也可以使用构造的第一个Graphics对象,并作为参数传递给DrawErrorPoint,而不是在DrawErrorPoint中重新构造一个。
Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias);Pen Pen(Color(255, Color(255,0,0,0));
RectF rc(sPt.x, sPt.y, ePt.x-sPt.x, ePt.y-sPt.y)
Pen.SetDashStyle(DashStyleSolid);
graphics.DrawRectangle(&Pen, rc);其中sPt为(600, -400) ePt为(2000, -1000);
为什么画不出来呢? RectF的最后两个参数要宽和高,该如何传递呢?