Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Scroll view & Print preview

Scroll view & Print preview

Scheduled Pinned Locked Moved C / C++ / MFC
c++tools
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nelson L
    wrote on last edited by
    #1

    Hi, I am a newbie using MFC. Most program scripts were copied from either books and examples. I encounter a difficulty when I wanna to scroll view and print preview. //====================== void CSLReaderView::OnDraw(CDC* pDC) { CSLReaderDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here //change the mapping mode pDC->SetMapMode(MM_LOENGLISH); //plot a rectanglar first, height 400 pixels, not shown in the script // display data here pDC->TextOut(100, -500, "RECORDING REPORT"); for (i=0; im_SLDA[i].LAi); pDC->TextOut(100, -540-i*20, s); } CSize docSize(100, 400+(N+10)*20); //doc size CRect rect; //cal page size GetClientRect(&rect); CSize pageSize(rect.right, rect.bottom); CSize lineSize(0, 20); //line size SetScrollSizes(MM_LOENGLISH, docSize, pageSize, lineSize); } void CSLReaderView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; sizeTotal.cx = sizeTotal.cy = 100; SetScrollSizes(MM_TEXT, sizeTotal); } void CSLReaderView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) { CSLReaderDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int pageHeight = pDC->GetDeviceCaps(VERTRES); //page height (dots) int logPixelsY = pDC->GetDeviceCaps(LOGPIXELSY); //dots/inch for pt int plotHeight = (int) (4.0*logPixelsY); //rectan->pixels for pt int lineHeight = (int) (0.2*logPixelsY); //line hight->pixels for pt int numPages = (pDoc->m_SLDA.GetSize()*lineHeight + plotHeight) / pageHeight + 1; pInfo ->SetMaxPage(numPages); } void CSLReaderView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { if (pDC->IsPrinting()) { int pageHeight = pDC->GetDeviceCaps(VERTRES); int OriginY = pageHeight * (pInfo->m_nCurPage-1); pDC->SetViewportOrg(0, -OriginY); } //CScrollView::OnPrepareDC(pDC, pInfo); //CONFLICT 1: if so, print preview can not show the 2nd page //CView::OnPrepareDC(pDC, pInfo); //CONFLICT 2: if so, view can not scroll } The conflict comes from the last two commands OnPrepareDC(), if use only the first, print preview can not show the 2nd page, i.e. all pages are the same. if use only the second, the view can not be scrolled properly in view. Thanks for your time. The code is long but I have no other ways to describe it better. Regards, Nelson:confused:

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups