VIEW中三个变量  
CImage imgOriginal;
int m_nFilterLoad;
SizesEnum m_nImageSize;void CeeeView::OnInitialUpdate()  // 加载并显示背景 
{
CFormView::OnInitialUpdate();
ResizeParentToFit();  for ( int i=0; i<4; ++i )
ti[i].x = ti[i].y = 50*i; ti[0].type = ti[2].type = TargetType::target;
ti[1].type = ti[3].type = TargetType::jam;
CString strFilter;
CSimpleArray<GUID> aguidFileTypes;
HRESULT hResult; hResult = imgOriginal.GetExporterFilterString(strFilter,aguidFileTypes);
if (FAILED(hResult)) {
CString fmt; 
return;
} if(FAILED(hResult)) {
return;
} imgOriginal.Destroy();
hResult = imgOriginal.Load(L"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Sunset.jpg");
if (FAILED(hResult)) {
 
return;
} m_nImageSize = SIZE_ORIGINAL;
Invalidate();
UpdateWindow();
}
void CeeeView::OnDraw(CDC* pDC)  // 动态显示小位图 
{
// TODO: 在此添加专用代码和/或调用基类  
CeeeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;     for ( int i=0; i<4; ++i )
   if ( true == ti[i].available )
   {
   CBitmap bmp;      BITMAP bmpInfo;
   if ( 0==ti[i].type  )
   bmp.LoadBitmap(IDB_BITMAP1);
  
   if ( 1==ti[i].type  )
   bmp.LoadBitmap(IDB_BITMAP2); 
   
   bmp.GetBitmap(&bmpInfo);
   // Create an in-memory DC compatible with the
   // display DC we're using to paint
   CDC dcMemory;
   dcMemory.CreateCompatibleDC(pDC);    // Select the bitmap into the in-memory DC
   CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);    // Find a centerpoint for the bitmap in the client area
   CRect rect;
   GetClientRect(&rect);
   ti[i].x +=10;
   int nX =  ti[i].x; 
   int nY = ti[i].y ;    // Copy the bits from the in-memory DC into the on-
   // screen DC to actually do the painting. Use the centerpoint
   // we computed for the target offset.
   pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 
   0, 0, SRCAND);    dcMemory.SelectObject(pOldBitmap); 
   }}
void CeeeView::OnPaint()  // 显示背景 



CPaintDC dc(this); // device context for painting
if (!imgOriginal.IsNull()) 
{ switch (m_nImageSize)
{
case SIZE_HALF:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth()/2,imgOriginal.GetHeight()/2,SRCCOPY);
break;
case SIZE_ORIGINAL:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth(),imgOriginal.GetHeight(),SRCCOPY);
break;
case SIZE_DOUBLE:
imgOriginal.StretchBlt(dc,0,0,imgOriginal.GetWidth()*2,imgOriginal.GetHeight()*2,SRCCOPY);
break;
case SIZE_FILL:
CRect rctWindowSize;
GetClientRect(rctWindowSize);
imgOriginal.StretchBlt(dc,0,0,rctWindowSize.Width(),rctWindowSize.Height(),SRCCOPY);
};
}

CView::OnPaint();
return; 
}程序在单独显示小位图 或背景时 都正常, 但希望它同时显示时 就什么都没显示了 请问为何 ? 如何解决 ?  谢谢  

解决方案 »

  1.   

    视图类就在OnDraw中绘图就行了,不要在OnPaint中绘制,因为CView::OnPaint()本身就会调用OnDraw,而里面就创建了一个CPaintDC。CPaintDC只能用于WM_PAINT消息中并且只能有一个。背景可以在OnDraw中一起绘制或者放在WM_ERASEBKGND消息响应函数(OnEraseBkgnd)中绘制。
      

  2.   

    对了,你的代码修改一下也可以,把CView::OnPaint()调用去掉,改为OnDraw(&dc)也可以实现。不过实在没必要。
      

  3.   

    那现在的onpaint函数怎么处理呢?  
      

  4.   

    我把onpaint中的代码放到 OnEraseBkgnd 中 背景显示出来了 但小位图没显示出阿 
      

  5.   

    还有个问题,你的是CFormView的继承类,那么默认不会有OnDraw。所以:
    void CeeeView::OnPaint()  // 显示背景 

        CPaintDC dc(this); // device context for painting 
        OnDraw(&dc); 
    } 即可。
      

  6.   

    谢谢 就是少了 
     CPaintDC dc(this); // device context for painting 
        OnDraw(&dc);