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