![]() |
Desktop Development »
Document / View »
General
Intermediate
Usage of the CScrollView class to add scrolling functionality to your applicationBy VGirishStep by step usage of the CScrollView class to add scrolling to your application |
VC6, VC7Win2K, WinXP, Visual Studio, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
Follow the following seven easy steps :-
Create a MDI Application by selecting Multiple Documents Interface in Step 1 of the app-wizard process.
In the 6th step, select the View class and in the combo box called base class
, select CScrollView and then click Finish.
Create the following variables in the View class (yourview.h file)
CDC m_MemDC;CBitmap m_bmpView;int m_nBmpWidth,m_nBmpHeight;In the View class , select the OnInitialUpdate function and
change the code like this.
void CMDIView::OnInitialUpdate() { CDC *pDC = this->GetDC(); m_MemDC.CreateCompatibleDC(pDC); m_bmpView.LoadBitmap(IDB_BMP_BKGND); // 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. m_MemDC.SelectObject(&m_bmpView); BITMAP Bitmap; m_bmpView.GetBitmap(&Bitmap); m_nBmpHeight = Bitmap.bmHeight; m_nBmpWidth = Bitmap.bmWidth; CSize size(m_nBmpWidth,m_nBmpHeight); SetScrollSizes(MM_TEXT,size); this->ReleaseDC(pDC); }
Select the OnDraw function and change the code inside like this
void CMDIView::OnDraw(CDC* pDC) { pDC->BitBlt(0,0,m_nBmpWidth,m_nBmpHeight, &m_MemDC,0,0,SRCCOPY); SetScrollSizes(MM_TEXT, CSize(m_nBmpWidth,m_nBmpHeight)); CChildFrame *pParentFrame = (CChildFrame *)this->GetParentFrame(); pParentFrame->RecalcLayout(); ResizeParentToFit(); }
To prevent flickering of the bitmap when its being scrolled, override the
View's OnEraseBkgnd and the ChildFrame's
OnEraseBkgnd like this.
BOOL CMDIView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
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.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 28 Jun 2002 Editor: Nishant Sivakumar |
Copyright 2002 by VGirish Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |