void CMapEditBy2003View::OnDraw(CDC* pDC)
{
CMapEditBy2003Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
/****************************************画背景****************************/
// 缓冲区DC
CDC* m_MemDC;
m_MemDC=new CDC;
CDC* copypDC;
copypDC=new CDC;
HBITMAP m_hTempBitmap; m_hTempBitmap=(HBITMAP)::LoadImage(NULL,pDoc->m_Map.m_BackGroud,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
    m_MemDC->CreateCompatibleDC(pDC);  //建立兼容dc
copypDC->CreateCompatibleDC(m_MemDC);

CRect rect;
GetClientRect(&rect); copypDC->SelectObject(m_hTempBitmap);  //选取图片
for(int i=0;i<pDoc->m_Map.m_iHeight/32;i++)   //将图片存入缓冲区
    for ( int j=0;j<pDoc->m_Map.m_iWidth/32;j++)
     {
          m_MemDC->BitBlt(i*32,   j*32,   32,   32,   
                    copypDC,   0,   0,   SRCCOPY   );   
     }

/******************************************************************/
    /**************************画选取的图片****************************/    
int h,w,x,y;
CString str;
tempImage->GetHeightAndWidth(h,w); 
tempImage->GetPos(x,y);
tempImage->GetID(str);
if(m_bitmap==NULL)
return ;
copypDC->SelectObject(m_bitmap);  //选取特定的图片
m_MemDC->BitBlt( x,   y,   w,   h,   
             copypDC,   0,   0,   SRCCOPY   );   

pDC->BitBlt(0,0,rect.right,rect.bottom,m_MemDC,0,0,SRCCOPY);    delete(copypDC);
delete(m_MemDC);

}//m_MemDC为缓冲区,我想现将copypDC的图象写到m_MemDC,然后在用pDC 画出来...
不知道为什么画不出来图象,如果直接将copyDC写到pDC上可以显示

解决方案 »

  1.   

    一段OnPaint中的函数,仅供参考:
    PAINTSTRUCT ps; 
        RECT rc;
        GetClientRect(&rc);

      HDC hDC = BeginPaint(&ps);
     
    //    FillRect(hDC, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
     
    //  if (m_bHaveScrollBar)
    //  DrawUpdateMessages(hDC);
    //  else
    //  DrawAllMessages(hDC);
    // 
    //  EndPaint(&ps);

    int nWidth = rc.right - rc.left;
    int nHeigth = rc.bottom - rc.top; if (m_hMemDC)
    ::DeleteDC(m_hMemDC);

    if (m_hBitmap)
    ::DeleteObject((HGDIOBJ)m_hBitmap); m_hMemDC = ::CreateCompatibleDC(hDC);
    m_hBitmap = ::CreateCompatibleBitmap(hDC, nWidth, nHeigth);
    ::SelectObject(m_hMemDC, m_hBitmap);
    FillRect(m_hMemDC, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
    if (m_bHaveScrollBar)
    DrawUpdateMessages(m_hMemDC);
    else
    DrawAllMessages(m_hMemDC);
    ::BitBlt(hDC, 0, 0, nWidth, nHeigth, m_hMemDC, 0, 0, SRCCOPY);
    ::EndPaint(m_hWnd, &ps); return TRUE;