内容如题!谢谢

解决方案 »

  1.   

    step by step
    1.从CView类派生一个类CBkgndView;
    2.重载该类的OnPaint函数,使其加载位图;
    3.在你的主窗口类加入一个CBkgndView类的成员变量 m_wndClient;
    4.重载主窗口的OnCreateClient;加入 m_wndClient.SubClassWindow(m_hWndMDIClient)。
      

  2.   

    BOOL CMyView::OnEraseBkgnd(CDC* pDC) 
    {
    if (!m_bitmap.m_hObject)
    return CFormView::OnEraseBkgnd(pDC);

    CFormView::OnEraseBkgnd(pDC);
    CRect rc;
    GetClientRect (rc);
    CDC dcImage;
    dcImage.CreateCompatibleDC (pDC);
    CBitmap *pOldBitmap =dcImage.SelectObject(&m_bitmap);

    // Get bitmap width and height
    BITMAP bm;
    m_bitmap.GetBitmap( &bm );

    // Use the minimum width and height
    int width = min (bm.bmWidth, rc.Width());
    int height = min (bm.bmHeight, rc.Height());

    // Draw the bitmap as the window background
    pDC->BitBlt (rc.Width()-width,0,width,height, &dcImage, 0, 0, SRCCOPY);

    // Release
    dcImage.SelectObject (pOldBitmap);
    dcImage.DeleteDC ();

    return true;
    }
    这是我搜索到的帖子。
      

  3.   

    我更改视图的背景为位图:
    void CTickDrawDoc::OnSelectBackpicture() 
    {
    // TODO: Add your command handler code here
    static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
    CFileDialog dlg(TRUE,"bmp",m_systemfilename,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
    if (dlg.DoModal() == IDOK)
    {
    m_systemfilename = dlg.GetFileName();
    m_bSystem = TRUE;
    UpdateAllViews(NULL);
    }
    }
    视图的ONdraw函数
    void CTickDrawView::OnDraw(CDC* pDC)
    {
    CTickDrawDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    CTickDrawApp *pApp = (CTickDrawApp*)AfxGetApp();
    CDC dc;
    CDC* pDrawDC = pDC;
    CBitmap bitmap;
    CBitmap* pOldBitmap=NULL; // only paint the rect that needs repainting
    CRect client;
    pDC->GetClipBox(client);
    CRect rect = client;
    DocToClient(rect);
    int width, height;
    width = pDoc->GetSize().cx;
    height = pDoc->GetSize().cy;
    if (width < rect.Width())
    width = rect.Width();
    if (height < rect.Height())
    height = rect.Height();
    if (!pDC->IsPrinting())
    { // draw to offscreen bitmap for fast looking repaints
    if (dc.CreateCompatibleDC(pDC))
    { if (bitmap.CreateCompatibleBitmap(pDC, width, height))
    //if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
    {
    OnPrepareDC(&dc, NULL);
    pDrawDC = &dc;
    // offset origin more because bitmap is just piece of the whole drawing
    dc.OffsetViewportOrg(-rect.left, -rect.top);
    pOldBitmap = dc.SelectObject(&bitmap);
    dc.SetBrushOrg(rect.left % 8, rect.top % 8);
    // might as well clip to the same rectangle
    dc.IntersectClipRect(client);
    }
    }
    } // paint background
    CBrush brush;
    if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
    return;
    brush.UnrealizeObject();
    if (!pDC->IsPrinting())
    {
    pDrawDC->FillRect(client, &brush);
    }
    DrawSystem(pDrawDC);
    pDoc->Draw(pDrawDC, this);
    if (pDrawDC != pDC)
    {
    pDC->SetViewportOrg(0, 0);
    pDC->SetWindowOrg(0,0);
    pDC->SetMapMode(MM_TEXT);
    dc.SetViewportOrg(0, 0);
    dc.SetWindowOrg(0,0);
    dc.SetMapMode(MM_TEXT);
    pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
    pDrawDC, 0, 0, SRCCOPY);
    if (pOldBitmap != NULL)
    dc.SelectObject(pOldBitmap);
    }
    }
      

  4.   

    重载OnDraw(CDC* pDC)
    {
       CBitmap bm;
       bm.LoadBitmap(IDB_*****); //<-你的位图资源ID
       CDC memDC;
       memDC.CreateCompatibleDC(pDC);
       memDC.SelectObject(&bm);
       pDC->BitBlt(0,0,***,***,&memDC,0,0,SRCCOPY); //***处为<-你的位图的宽度和高度
       memDC.DeleteDC();
    }