OnPrepareDC
William Drew -- solset@cais.com Sunday, February 16, 1997 This is from the Remarks section of on-line help for OnPrepareDC: "Called by the framework before the OnDraw member function is called for screen display and before the OnPrint member function is called for each page during printing or print preview. The default implementation of this function does nothing if the function is called for screen display. However, this function is overridden in derived classes, such as CScrollView, to adjust attributes of the device context; consequently, you should always call the base class implementation at the beginning of your override." Some additional information. 1) The class CCnntyPlnView is derived from CScrollView. 2) This is the code in OnInitialUpdate. void CCnntyPlnView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CCnntyPlnDoc* pDoc = GetDocument(); GetParentFrame()->RecalcLayout(); CSize mysize(75,75); SetScaleToFitSize( mysize ); } 3) The OnDraw code is: void CCnntyPlnView::OnDraw(CDC* pDC) { CCnntyPlnDoc* pDoc = GetDocument(); if(!AfxIsValidAddress(pDoc, sizeof(CDocument))) return; if(!AfxIsValidAddress(pDC, sizeof(CDC))) return; CFont* pFont; m_Font.Detach( ); m_Font.CreatePointFont( 6, (LPCTSTR) "Fixed", pDC); pDC->SelectObject( m_Font ); CUIObjCore* pObj = pDoc->GridObj(); // could be a cplan or xpdr if(VALID_ADDR(pObj, CUIObjCore)) { if( pObj->IsKindOf(RUNTIME_CLASS(CCnntyPln))) { CCnntyPln* pCPlan = (CCnntyPln*) pObj; DrawCPlan(pDC); } else if( pObj->IsKindOf(RUNTIME_CLASS(CXpdr))) { CXpdr* pXpdr = (CXpdr*) pObj; } } pDC->SelectObject( pFont ); if(VALID_ADDR(pFont, CFont)) pFont->DeleteObject( ); } // end of OnDraw The OnDraw code works fine until I override OnPrepareDC as shown below. void CCnntyPlnView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { CScrollView::OnPrepareDC(pDC, pInfo); GetParentFrame()->RecalcLayout(); CSize mysize(75,75); SetScaleToFitSize( mysize ); } Any direction would be appreciated. --------------------- William J. Drew Solution Set, Inc. solset@cais.com Environment: VC++ 4.2-flat, NT 4.0
Dulepov Dmitry -- dima@ssm6000.samsung.ru Monday, February 17, 1997 [Mailer: "Groupware E-Mail". Version 1.03.000] > [From: William Drew >This is from the Remarks section of on-line help for OnPrepareDC: > >"...However, this function is overridden in derived >classes, such as CScrollView, to adjust attributes of the device >context; consequently, you should always call the base class >implementation at the beginning of your override." > > >void CCnntyPlnView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) >{ > CScrollView::OnPrepareDC(pDC, pInfo); > GetParentFrame()->RecalcLayout(); > CSize mysize(75,75); > SetScaleToFitSize( mysize ); >} > 1. What the reason to call GetParentFrame()->RecalcLayout() in OnPrepareDC() ? This is a drawing only function. What do you want to do? 2. What do you mean by "The OnDraw code works fine until I override OnPrepareDC as shown below" ? What do you see on the screen ? Dmitry A. Dulepov Samsung Electronics Co., Ltd. Russian Research Center Phone: +7 (095) 213-9207 Fax: +7 (095) 213-9196 E-mail: dima@src.samsung.ru ====================================
Become an MFC-L member | Вернуться в корень Архива |