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. Print-Layout View implementation

Print-Layout View implementation

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
5 Posts 2 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.
  • M Offline
    M Offline
    Maverick
    wrote on last edited by
    #1

    When drawing to a CView you normally draw onto the whole client area of its attached CFrameWnd, ryt? Now I want to implement a Print-Layout View (in MS Word)/ Print-Preview style view wherein you could see the page, and the view doesn't occupy the whole client area of the frame window... Any suggestions? article or link where i can get some information regarding this.. tnx a lot.. in advance ;) maverick "watch the birdie!"

    J 1 Reply Last reply
    0
    • M Maverick

      When drawing to a CView you normally draw onto the whole client area of its attached CFrameWnd, ryt? Now I want to implement a Print-Layout View (in MS Word)/ Print-Preview style view wherein you could see the page, and the view doesn't occupy the whole client area of the frame window... Any suggestions? article or link where i can get some information regarding this.. tnx a lot.. in advance ;) maverick "watch the birdie!"

      J Offline
      J Offline
      Jack Puppy
      wrote on last edited by
      #2

      CWinApp::CreatePrinterDC will give you a dc for the active printer, and pDC->GetDeviceCaps(PHYSICALWIDTH), pDC->GetDeviceCaps(PHYSICALHEIGHT) will give you the paper dimensions. Once you have the dimensions, fill the background with a color of your choice, and then use the dimensions to draw a white "paper" rectangle using pDC->Rectangle. If you want zooming, you'd have to use SetWindowExt/SetViewportExt in OnPrepareDC to set your zoom level.

      :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
      Painted on the side of a dog trainer's van: SIT HAPPENS

      M 2 Replies Last reply
      0
      • J Jack Puppy

        CWinApp::CreatePrinterDC will give you a dc for the active printer, and pDC->GetDeviceCaps(PHYSICALWIDTH), pDC->GetDeviceCaps(PHYSICALHEIGHT) will give you the paper dimensions. Once you have the dimensions, fill the background with a color of your choice, and then use the dimensions to draw a white "paper" rectangle using pDC->Rectangle. If you want zooming, you'd have to use SetWindowExt/SetViewportExt in OnPrepareDC to set your zoom level.

        :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
        Painted on the side of a dog trainer's van: SIT HAPPENS

        M Offline
        M Offline
        Maverick
        wrote on last edited by
        #3

        Hey Thanks for this info.. Well, I don't want a print preview per se.. Just want my interface to be that way, with zooming and scrolling.. Anyway, thanks again. This will be a good help as well... regards, Anton "watch the birdie!..."

        1 Reply Last reply
        0
        • J Jack Puppy

          CWinApp::CreatePrinterDC will give you a dc for the active printer, and pDC->GetDeviceCaps(PHYSICALWIDTH), pDC->GetDeviceCaps(PHYSICALHEIGHT) will give you the paper dimensions. Once you have the dimensions, fill the background with a color of your choice, and then use the dimensions to draw a white "paper" rectangle using pDC->Rectangle. If you want zooming, you'd have to use SetWindowExt/SetViewportExt in OnPrepareDC to set your zoom level.

          :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
          Painted on the side of a dog trainer's van: SIT HAPPENS

          M Offline
          M Offline
          Maverick
          wrote on last edited by
          #4

          If you look at MS Word, with a new blank document.. and then choose View->Print Layout menu.. Now, you'll see the white page on the brown/gray background.. on a 100% view I know that on normal circumstances, the client area of CView entirely occupies the client area of the CCHildFrame.. Now with the Print-Layout View, Is it possible that the white page is drawn on the CView client area but it is NOT occupying the whole client area of CCHIldFrame so thats why we are seeing the background color of CChildFrame? Or is the white page and the background color are all drawn together in the client area of CView? Maverick "watch the birdie!..."

          J 1 Reply Last reply
          0
          • M Maverick

            If you look at MS Word, with a new blank document.. and then choose View->Print Layout menu.. Now, you'll see the white page on the brown/gray background.. on a 100% view I know that on normal circumstances, the client area of CView entirely occupies the client area of the CCHildFrame.. Now with the Print-Layout View, Is it possible that the white page is drawn on the CView client area but it is NOT occupying the whole client area of CCHIldFrame so thats why we are seeing the background color of CChildFrame? Or is the white page and the background color are all drawn together in the client area of CView? Maverick "watch the birdie!..."

            J Offline
            J Offline
            Jack Puppy
            wrote on last edited by
            #5

            Here's a very simple implementation that simulates drawing a page. First, create an SDI project that uses CScrollview as its view class. Make the following changes to the myview.cpp file. 1) Add two constants to the top of the file: // Origin for the top/left of the paper CPoint g_ptOrigin(50,50); // Paper dimensions (simulates a 8.5 x 11" page) CRect g_rcPaper(0, 0, 850, 1100); 2) In the OnDraw function, insert the following code: pDC->SetBkMode(TRANSPARENT); pDC->Rectangle(g_rcPaper); pDC->TextOut(50, 50, _T("This is a test")); 3) Create an override for OnPrepareDC, and insert the following code after the call to the base class: // Map the logical origin to the device origin // This makes the top left of the client area act like (-50,-50), and the top/left of the page act like (0,0) pDC->OffsetWindowOrg(-g_ptOrigin.x, -g_ptOrigin.y); 4) Add a handler for the ON_WM_ERASEBKGND message and replace with the following code: CRect rcClient; GetClientRect(rcClient); pDC->FillSolidRect(rcClient, RGB(127,127,127)); return (TRUE); - Step 4 draws your gray background - Step 3 offsets the dc origin so that drawing is relative to the top left of the paper, not the top left of the client area - Step 2 draws the paper, with the offset in place

            :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
            Painted on the side of a dog trainer's van: SIT HAPPENS

            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