本帖最后由 VisualEleven 于 2012-09-16 12:29:13 编辑

解决方案 »

  1.   

    你意思这个两个函数OnPaint()和RadarPanelShow1()互相调用?
     CPaintDC dc(this)只要都用了这个,没关系啊。保证资源不冲突,又没技术含量的。
      

  2.   

    我的意思这个是用函数OnPaint()调用RadarPanelShow1()函数,把OnPaint()里面if判断以后的语句都放在RadarPanelShow1()函数里面,我一直没有没有调试出来结果,不知道是哪儿出问题了?
      

  3.   

    要把 CPaintDC dc(this); // device context for painting

    void CMeter::RadarPanelShow1(CPaintDC *pDC)
    函数内不得
    GETDC();
      

  4.   

    schlafenhamster嗯,我发现也是这部分出现了问题,但是一直没有调通,这个问题的原因是不是因为对象指针没有传递过来呢?接下来我把RadarPanelShow1()函数里的dc都改成pdc就行了吗?
      

  5.   

    CPaintDC *pDC 是你操作对象,没有他你没法输出。
    函数里的dc都改成pdc就行了。
    函数里的dc是你GetDC来的吧? 这个DC 不是PaintDC。 
      

  6.   

    schlafenhamster
    你好,我没有调通,程序只进到if(showflag==1),之后if(showflag==2)的位图加载就进不去了,这是什么问题引起的呢?
    我把Test()函数里的dc都改成pdc,程序不报错,但是一运行就出现问题自动关闭,你帮我看下
    程序如下:
    void CMeter::OnPaint() 
    { CPaintDC* pdc; // device context for painting

    //对应控件位置扇扫实现
    if(this==Pm_myMeter)
    {
         Test(pdc);
            }
    }
    void CMeter::Test(CPaintDC* pdc)
    {
    // 获得控件区域
    CPaintDC dc(this); // device context for painting //CPaintDC* pdc;
    // 获得控件区域
    GetClientRect (&m_rectCtrl);

    CMemDC memDC(&dc, &m_rectCtrl);

    //填充客户区颜色
    memDC.FillSolidRect(&m_rectCtrl,RGB(0,0,0));

    //位图加载
    CBitmap bitmap;
    bitmap.LoadBitmap(IDB_BITMAP1);

    BITMAP bmp;
    bitmap.GetBitmap(&bmp);

    CDC dcCompatible;
    dcCompatible.CreateCompatibleDC(memDC);

    dcCompatible.SelectObject(&bitmap);

    CRect rect;
    GetClientRect(&rect);
    memDC->BitBlt(50,5,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
        
    static int showflag=0;
    showflag++;
    if(showflag==7)
    {
    showflag=1;
    }
    if(showflag==1)
    {

    //余辉位图加载实现
    CBitmap bitmap2;
    bitmap2.LoadBitmap(IDB_BITMAP2);
    bitmap2.GetBitmap(&bmp);
    CDC dcCompatible2;
    dcCompatible2.CreateCompatibleDC(memDC);
    dcCompatible2.SelectObject(&bitmap2);
    GetClientRect(&rect);
    memDC->BitBlt(224,48,rect.Width(),rect.Height(),&dcCompatible2,0,0, SRCPAINT);
    }

    if(showflag==2)
    {
    CBitmap bitmap3;
    bitmap3.LoadBitmap(IDB_BITMAP3);
    bitmap3.GetBitmap(&bmp);
    CDC dcCompatible3;
    dcCompatible3.CreateCompatibleDC(memDC);
    dcCompatible3.SelectObject(&bitmap3);
    GetClientRect(&rect);
    memDC->BitBlt(90,48,rect.Width(),rect.Height(),&dcCompatible3,0,0, SRCPAINT);
    }
    if(showflag==3)
    { CBitmap bitmap4;
    bitmap4.LoadBitmap(IDB_BITMAP4);
    bitmap4.GetBitmap(&bmp);
    CDC dcCompatible4;
    dcCompatible4.CreateCompatibleDC(memDC);
    dcCompatible4.SelectObject(&bitmap4);
    GetClientRect(&rect);
    memDC->BitBlt(90,48,rect.Width(),rect.Height(),&dcCompatible4,0,0, SRCPAINT);
    }
      
    if(showflag==4)
    {
    CBitmap bitmap5;
    bitmap5.LoadBitmap(IDB_BITMAP5);
    bitmap5.GetBitmap(&bmp);
    CDC dcCompatible5;
    dcCompatible5.CreateCompatibleDC(memDC);
    dcCompatible5.SelectObject(&bitmap5);
    GetClientRect(&rect);
    memDC->BitBlt(90,181,rect.Width(),rect.Height(),&dcCompatible5,0,0, SRCPAINT);
    }
      

    if(showflag==5)
    { CBitmap bitmap6;
    bitmap6.LoadBitmap(IDB_BITMAP6);
    bitmap6.GetBitmap(&bmp);
    CDC dcCompatible6;
    dcCompatible6.CreateCompatibleDC(memDC);
    dcCompatible6.SelectObject(&bitmap6);
    GetClientRect(&rect);
    memDC->BitBlt(90,181,rect.Width(),rect.Height(),&dcCompatible6,0,0, SRCPAINT);
    } if(showflag==6)
    {
    CBitmap bitmap7;
    bitmap7.LoadBitmap(IDB_BITMAP7);
    bitmap7.GetBitmap(&bmp);
    CDC dcCompatible7;
    dcCompatible7.CreateCompatibleDC(memDC);
    dcCompatible7.SelectObject(&bitmap7);
    GetClientRect(&rect);
    memDC->BitBlt(224,48,rect.Width(),rect.Height(),&dcCompatible7,0,0, SRCPAINT);
    }
      

  7.   

    void CMeter::Test(CPaintDC* pdc)
    {
    // 获得控件区域
    CPaintDC dc(this); // device context for painting
    怎么又出来个dc ?
    在test不要任何getdc 的语句(包括CPaintDC dc(this); )
      

  8.   

    我把Test(CPaintDC* pdc)里面的CPaintDC dc(this)注释掉, 程序里面的所以dc都替换为pdc后程序没有错误,就是运行不了,为什么呢?
      

  9.   

    "就是运行不了"
    进没进 test
    一步一步调
      

  10.   

    哦了,解决了,我在调用Test(pdc)时对pdc加上&就行了,谢谢你!