Click here to Skip to main content
12,997,146 members (72,466 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 28 Jun 2002

Usage of the CScrollView class to add scrolling functionality to your application

, 28 Jun 2002
Rate this:
Please Sign up or sign in to vote.
Step by step usage of the CScrollView class to add scrolling to your application


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 :-

Step 1

Create a MDI Application by selecting Multiple Documents Interface in Step 1 of the app-wizard process.

Step 2

In the 6th step, select the View class and in the combo box called base class , select CScrollView and then click Finish.

Step 3

Create the following variables in the View class (yourview.h file)

  • CDC m_MemDC;
  • CBitmap m_bmpView;
  • int m_nBmpWidth,m_nBmpHeight;

Step 4

In the View class , select the OnInitialUpdate function and change the code like this.

void CMDIView::OnInitialUpdate() 
    CDC *pDC = this->GetDC();


    // Here IDB_BMP_BKGND is a bitmap included in the resource
    // Note : You can also load a bitmap from a file in the 
    // hard disk instead of using the bmp in the resource.


    BITMAP Bitmap;

    m_nBmpHeight = Bitmap.bmHeight;
    m_nBmpWidth = Bitmap.bmWidth;

    CSize size(m_nBmpWidth,m_nBmpHeight);


Step 5

Select the OnDraw function and change the code inside like this

void CMDIView::OnDraw(CDC* pDC)

    SetScrollSizes(MM_TEXT, CSize(m_nBmpWidth,m_nBmpHeight));
    CChildFrame *pParentFrame =
        (CChildFrame *)this->GetParentFrame();

Step 6

To prevent flickering of the bitmap when its being scrolled, override the View's OnEraseBkgnd and the ChildFrame's

like this.

BOOL CMDIView::OnEraseBkgnd(CDC* pDC) 
    return TRUE;

BOOL CChildFrame::OnEraseBkgnd(CDC* pDC) 
    return FALSE;

Step 7

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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionChildFrame????? Pin
Furries25-Nov-04 2:28
memberFurries25-Nov-04 2:28 
AnswerRe: ChildFrame????? Pin
PeteOlcott19-Aug-07 5:22
memberPeteOlcott19-Aug-07 5:22 
GeneralThanks Pin
Ajay_Chopra17-Jun-04 2:15
memberAjay_Chopra17-Jun-04 2:15 
GeneralAre these calls all needed Pin
CJN8-Oct-03 21:50
memberCJN8-Oct-03 21:50 
QuestionHow to load bitmap from disk file Pin
CJN8-Oct-03 16:02
memberCJN8-Oct-03 16:02 
AnswerRe: How to load bitmap from disk file Pin
Anonymous14-Oct-04 2:25
sussAnonymous14-Oct-04 2:25 
GeneralRe: How to load bitmap from disk file Pin
shizulooi13-Jul-09 23:01
membershizulooi13-Jul-09 23:01 
GeneralTop of the class Pin
Andy Kuiper30-May-03 2:05
sussAndy Kuiper30-May-03 2:05 
Generalthanks Pin
Anonymous3-Sep-02 19:36
sussAnonymous3-Sep-02 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170622.1 | Last Updated 29 Jun 2002
Article Copyright 2002 by VGirish
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid