This code helps you to load a bitmap from a resource or from a file and show
it in a MDI View. It enables scrolling and also scrolls the bitmap accordingly.
Steps to follow
Follow the following seven easy steps :-
Create a MDI Application by selecting Multiple Documents Interface in Step 1 of the
In the 6th step, select the View class and in the combo box called base class
CScrollView and then click Finish.
Create the following variables in the View class (yourview.h file)
In the View class , select the
OnInitialUpdate function and
change the code like this.
CDC *pDC = this->GetDC();
m_nBmpHeight = Bitmap.bmHeight;
m_nBmpWidth = Bitmap.bmWidth;
OnDraw function and change the code inside like this
void CMDIView::OnDraw(CDC* pDC)
CChildFrame *pParentFrame =
To prevent flickering of the bitmap when its being scrolled, override the
OnEraseBkgnd and the
BOOL CMDIView::OnEraseBkgnd(CDC* pDC)
BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
Compile your project and run it. That's it. Now, you have a scrolling window
which displays a bitmap too. All luck and have a great time.