代码如下:
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+绘图则不会出现刷新问题,请高手出招.

解决方案 »

  1.   

    用一个内存Graphics画好再贴上去吧
      

  2.   

    只用一个Graphics对象,而不是两个。
      

  3.   

    DentistryDoctor(MVP-My heart will fly,in the sky.) 
    只用一个Graphics对象,而不是两个。可是我要改变CDC的映射模式.
      

  4.   

    可以得到HDC,graphics.GetHDC();只传一个不知道是什么问题?
      

  5.   

    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);
    }
    这样就行了(加了大括号),弱智问题,为什么?你还问为什么,看MSDN吧,还那么多星星呢。
      

  6.   

    hollysky(爱神):高手啊!请讲讲为什么.
      

  7.   

    是不是因为graphics对象在最后一个函数调用时还没有释放?
      

  8.   

    实际上很简单,因为一个Graphics对象还存在的时候,构造另一个Graphics就会造成显示下不正确。而最后一个回答是在DrawErrorPoint(pDC, m_Position);之前先让前一个Graphics对象结束其生命周期。
    你也可以使用构造的第一个Graphics对象,并作为参数传递给DrawErrorPoint,而不是在DrawErrorPoint中重新构造一个。
      

  9.   

    感谢两位高手,问题已解决了.现在还有一个问题想请问各位大侠: 
    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的最后两个参数要宽和高,该如何传递呢?
      

  10.   

    RectF   rc(sPt.x, sPt.y, fabs(ePt.x-sPt.x), fabs(ePt.y-sPt.y));同样不行,虽然能画出,但是位置不对.