//TestView.h
...
public:
CBitmap *pMemBitmap;
CDC *pMemDC;
...
//TestView.cpp
CTestView::CTestView()
{
// TODO: 
m_ntime    = 0;
pMemBitmap = new CBitmap;
pMemDC     = new CDC;
}CTestView::~CTestView()
{
delete pMemBitmap;
delete pMemDC;
}void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: 
pMemDC->CreateCompatibleDC(NULL);
pMemBitmap->CreateCompatibleBitmap(pDC,nWidth,nHeight); OnTimer(1);
}void CTestView::OnTimer(UINT nIDEvent) 
{
// TODO: 
CClientDC dc(this);
int nx, ny; m_ntime++; nx = dc.GetDeviceCaps(HORZRES)/2;
ny = dc.GetDeviceCaps(VERTRES)/2; CBitmap *pOldBit = dc.SelectObject(pMemBitmap); pMemDC->FillSolidRect(0,0,nWidth,nHeight,RGB(168,168,168));
pMemDC->Ellipse(nx + m_ntime, ny + m_ntime, nx + m_ntime, ny + m_ntime); dc.BitBlt(0,0,nWidth,nHeight,pMemDC,0,0,SRCCOPY); Invalidate(); CView::OnTimer(nIDEvent);
}void CTestView::OnInitialUpdate() 
{
CView::OnInitialUpdate();

// TODO: 
SetTimer(1, 100, NULL);
nWidth = nHeight = 1000;
}

解决方案 »

  1.   

    pMemDC->CreateCompatibleDC(NULL);
    应该为
    pDC->CreateCompatibleDC(pMemDC)
      

  2.   

    Erro!!!
    void CTestView::OnDraw(CDC* pDC)
    {
    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: 
    pMemDC->CreateCompatibleDC(pDC);                      
    pMemBitmap->CreateCompatibleBitmap(pMemDC,nWidth,nHeight); OnTimer(100);
    }void CTestView::OnTimer(UINT nIDEvent) 
    {
    // TODO: 
    CClientDC dc(this);
    int nx, ny; m_ntime++; nx = dc.GetDeviceCaps(HORZRES)/2;
    ny = dc.GetDeviceCaps(VERTRES)/2; CBitmap *pOldBit = pMemDC->SelectObject(pMemBitmap); pMemDC->FillSolidRect(0,0,nWidth,nHeight,RGB(168,168,168));
    pMemDC->Ellipse(nx + m_ntime, ny + m_ntime, nx + m_ntime, ny + m_ntime); dc.BitBlt(0,0,nWidth,nHeight,pMemDC,0,0,SRCCOPY); //Invalidate(); //CView::OnTimer(nIDEvent);
    }
      

  3.   

    void CTestView::OnDraw(CDC* pDC)
    {
    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: 
    pMemDC->CreateCompatibleDC(pDC);                      
    pMemBitmap->CreateCompatibleBitmap(pMemDC,nWidth,nHeight); //OnTimer(100);
    }
      

  4.   

    it should be like this:
    //TestView.h
    ...
    public:
    CBitmap *pMemBitmap;
    CDC *pMemDC;
             int m_nflag;
    ...CTestView::CTestView()
    {
    // TODO: 
    m_ntime    = 0;
             m_nflag    = 0;
    pMemBitmap = new CBitmap;
    pMemDC     = new CDC;
    }void CTestView::OnDraw(CDC* pDC)
    {
    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: 
             if (m_nflag == 0)
             {
       pMemDC->CreateCompatibleDC(NULL);
       pMemBitmap->CreateCompatibleBitmap(pDC,nWidth,nHeight);    CBitmap *pOldBit = dc.SelectObject(pMemBitmap);
                m_nflag = 1;
              } OnTimer(1);
    }void CTestView::OnTimer(UINT nIDEvent) 
    {
    // TODO: 
    CClientDC dc(this);
    int nx, ny; m_ntime++; nx = dc.GetDeviceCaps(HORZRES)/2;
    ny = dc.GetDeviceCaps(VERTRES)/2; pMemDC->FillSolidRect(0,0,nWidth,nHeight,RGB(168,168,168));
    pMemDC->Ellipse(nx + m_ntime, ny + m_ntime, nx + m_ntime, ny + m_ntime); dc.BitBlt(0,0,nWidth,nHeight,pMemDC,0,0,SRCCOPY); Invalidate(); CView::OnTimer(nIDEvent);
    }