11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10. Bitmap<br />

BITMAP bm;<br />

……<br />

}<br />

if(m_bmpBkd.GetSafeHandle() == NULL)<br />

{<br />

m_bmpBkd.LoadBitmap(IDB_BITMAPBKD);<br />

m_bmpBkd.GetBitmap(&bm);<br />

m_bmpBkd.SetBitmapDimension(bm.bmWidth, bm.bmHeight);<br />

ASSERT(m_bmpBkd.GetSafeHandle());<br />

}<br />

CScrollView::OnInitialUpdate();<br />

The bitmap can also be loaded in the constructor of CGDIView.<br />

To paint the background of a window, we need to handle message WM_ERASEBKGND and implement<br />

background drawing by ourseleves in the message hanlder. In the sample, this message handler is added<br />

through using Class Wizard, and the corresponding function is implemented as follows:<br />

BOOL CGDIView::OnEraseBkgnd(CDC* pDC)<br />

{<br />

CDC dcMem;<br />

CBitmap *pBmpOld;<br />

int i, j;<br />

int nRepX, nRepY;<br />

CRect rect;<br />

CSize size;<br />

CPoint pt;<br />

}<br />

pt=GetScrollPosition();<br />

dcMem.CreateCompatibleDC(pDC);<br />

pBmpOld=dcMem.SelectObject(&m_bmpBkd);<br />

size=m_bmpBkd.GetBitmapDimension();<br />

GetClientRect(rect);<br />

rect.right+=pt.x;<br />

rect.bottom+=pt.y;<br />

nRepX=(rect.Width()+size.cx-1)/size.cx;<br />

nRepY=(rect.Height()+size.cy-1)/size.cy;<br />

for(i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!