|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis 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 followFollow the following seven easy steps :- Step 1Create a MDI Application by selecting Multiple Documents Interface in Step 1 of the app-wizard process. Step 2In the 6th step, select the View class and in the combo box called base class
, select Step 3Create the following variables in the View class (yourview.h file)
Step 4In the View class , select the 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); } Step 5Select the 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(); } Step 6To prevent flickering of the bitmap when its being scrolled, override the
View's BOOL CMDIView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
Step 7Compile 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||