回覆列表
  • 1 # 鶴駝

    IDB_BG 是點陣圖資源的ID

    方法一 OnEraseBkgnd(CDC* pDC)

    {

    // 設定畫刷為希望的背景

    CDC backBmp;

    backBmp.CreateCompatibleDC(pDC);

    CBitmap bitmap;

    bitmap.LoadBitmap(IDB_BG);

    CBrush m_brushBackground;

    m_brushBackground.CreatePatternBrush(&bitmap); ///建立點陣圖畫刷

    CBrush* pOldMemDCBrush = pDC->SelectObject(&m_brushBackground);

    pDC->PatBlt(0, 0, m_ScrollRect.Width(), m_ScrollRect.Height(), PATCOPY);

    pDC->SelectObject(pOldMemDCBrush);

    return TRUE;

    }

    方法二 OnEraseBkgnd(CDC* pDC)

    {

    CBitmap m_pMap;

    m_pMap.LoadBitmap(IDB_BG);

    CRect rect;

    GetClientRect(&rect);

    BITMAP bm;

    CDC dcMem;

    m_pMap.GetObject(sizeof(BITMAP), &bm);

    dcMem.CreateCompatibleDC(pDC);

    CBitmap* pOldBitmap = dcMem.SelectObject(&m_pMap);

    for (register int nX = 0; nX < rect.right - rect.left; nX += bm.bmWidth)

    for (int nY = 0; nY < rect.bottom - rect.top; nY += bm.bmHeight)

    pDC->BitBlt(nX, nY, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);

    dcMem.SelectObject(pOldBitmap);

    return TRUE;

    }

    方法三 OnEraseBkgnd(CDC* pDC)

    {

    CBitmap bmp;

    bmp.LoadBitmap(IDB_BG); ///載入點陣圖

    CBrush m_brushBackground;

    m_brushBackground.CreatePatternBrush(&bmp); ///建立點陣圖畫刷

    CRect rect;

    GetClientRect(&rect);

    pDC->FillRect(rect, &m_brushBackground); //用背景畫填充區域

    return TRUE;

    }

  • 中秋節和大豐收的關聯?
  • 為什麼清朝皇帝普遍比明朝皇帝長壽?