1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/printing.cpp
3 // Purpose: Printing demo for wxWidgets
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #if !wxUSE_PRINTING_ARCHITECTURE
24 #error "You must set wxUSE_PRINTING_ARCHITECTURE to 1 in setup.h, and recompile the library."
27 // Set this to 1 if you want to test PostScript printing under MSW.
28 // However, you'll also need to edit src/msw/makefile.nt.
29 #define wxTEST_POSTSCRIPT_IN_MSW 0
32 #include "wx/metafile.h"
34 #include "wx/printdlg.h"
38 #if wxTEST_POSTSCRIPT_IN_MSW
39 #include "wx/generic/printps.h"
40 #include "wx/generic/prntdlgg.h"
44 #include "wx/mac/printdlg.h"
50 #include "mondrian.xpm"
54 MyFrame
*frame
= (MyFrame
*) NULL
;
55 // int orientation = wxPORTRAIT;
57 // Global print data, to remember settings during the session
58 wxPrintData
*g_printData
= (wxPrintData
*) NULL
;
60 // Global page setup data
61 wxPageSetupDialogData
* g_pageSetupData
= (wxPageSetupDialogData
*) NULL
;
66 // Writes a header on a page. Margin units are in millimetres.
67 bool WritePageHeader(wxPrintout
*printout
, wxDC
*dc
, const wxChar
*text
, float mmToLogical
);
69 // The `main program' equivalent, creating the windows and returning the
72 bool MyApp::OnInit(void)
74 if ( !wxApp::OnInit() )
77 wxInitAllImageHandlers();
79 m_testFont
.Create(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
81 g_printData
= new wxPrintData
;
82 // You could set an initial paper size here
83 // g_printData->SetPaperId(wxPAPER_LETTER); // for Americans
84 // g_printData->SetPaperId(wxPAPER_A4); // for everyone else
86 g_pageSetupData
= new wxPageSetupDialogData
;
87 // copy over initial paper size from print record
88 (*g_pageSetupData
) = *g_printData
;
89 // Set some initial page margins in mm.
90 g_pageSetupData
->SetMarginTopLeft(wxPoint(15, 15));
91 g_pageSetupData
->SetMarginBottomRight(wxPoint(15, 15));
93 // Create the main frame window
94 frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets Printing Demo"),
95 wxPoint(0, 0), wxSize(400, 400));
98 // Give it a status line
99 frame
->CreateStatusBar(2);
100 #endif // wxUSE_STATUSBAR
102 // Load icon and bitmap
103 frame
->SetIcon( wxICON( mondrian
) );
106 wxMenu
*file_menu
= new wxMenu
;
108 file_menu
->Append(WXPRINT_PRINT
, _T("&Print..."), _T("Print"));
109 file_menu
->Append(WXPRINT_PAGE_SETUP
, _T("Page Set&up..."), _T("Page setup"));
111 file_menu
->Append(WXPRINT_PAGE_MARGINS
, _T("Page Margins..."), _T("Page margins"));
113 file_menu
->Append(WXPRINT_PREVIEW
, _T("Print Pre&view"), _T("Preview"));
117 wxAcceleratorEntry entries
[1];
118 entries
[0].Set(wxACCEL_CTRL
, (int) 'V', WXPRINT_PREVIEW
);
119 wxAcceleratorTable
accel(1, entries
);
120 frame
->SetAcceleratorTable(accel
);
123 #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
124 file_menu
->AppendSeparator();
125 file_menu
->Append(WXPRINT_PRINT_PS
, _T("Print PostScript..."), _T("Print (PostScript)"));
126 file_menu
->Append(WXPRINT_PAGE_SETUP_PS
, _T("Page Setup PostScript..."), _T("Page setup (PostScript)"));
127 file_menu
->Append(WXPRINT_PREVIEW_PS
, _T("Print Preview PostScript"), _T("Preview (PostScript)"));
130 file_menu
->AppendSeparator();
131 file_menu
->Append(WXPRINT_ANGLEUP
, _T("Angle up\tAlt-U"), _T("Raise rotated text angle"));
132 file_menu
->Append(WXPRINT_ANGLEDOWN
, _T("Angle down\tAlt-D"), _T("Lower rotated text angle"));
133 file_menu
->AppendSeparator();
134 file_menu
->Append(WXPRINT_QUIT
, _T("E&xit"), _T("Exit program"));
136 wxMenu
*help_menu
= new wxMenu
;
137 help_menu
->Append(WXPRINT_ABOUT
, _T("&About"), _T("About this demo"));
139 wxMenuBar
*menu_bar
= new wxMenuBar
;
141 menu_bar
->Append(file_menu
, _T("&File"));
142 menu_bar
->Append(help_menu
, _T("&Help"));
144 // Associate the menu bar with the frame
145 frame
->SetMenuBar(menu_bar
);
147 MyCanvas
*canvas
= new MyCanvas(frame
, wxPoint(0, 0), wxSize(100, 100), wxRETAINED
|wxHSCROLL
|wxVSCROLL
);
149 // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
150 canvas
->SetScrollbars(20, 20, 50, 50);
152 frame
->canvas
= canvas
;
154 frame
->Centre(wxBOTH
);
158 frame
->SetStatusText(_T("Printing demo"));
159 #endif // wxUSE_STATUSBAR
169 delete g_pageSetupData
;
173 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
174 EVT_MENU(WXPRINT_QUIT
, MyFrame::OnExit
)
175 EVT_MENU(WXPRINT_PRINT
, MyFrame::OnPrint
)
176 EVT_MENU(WXPRINT_PREVIEW
, MyFrame::OnPrintPreview
)
177 EVT_MENU(WXPRINT_PAGE_SETUP
, MyFrame::OnPageSetup
)
178 EVT_MENU(WXPRINT_ABOUT
, MyFrame::OnPrintAbout
)
179 #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
180 EVT_MENU(WXPRINT_PRINT_PS
, MyFrame::OnPrintPS
)
181 EVT_MENU(WXPRINT_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
182 EVT_MENU(WXPRINT_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
185 EVT_MENU(WXPRINT_PAGE_MARGINS
, MyFrame::OnPageMargins
)
187 EVT_MENU(WXPRINT_ANGLEUP
, MyFrame::OnAngleUp
)
188 EVT_MENU(WXPRINT_ANGLEDOWN
, MyFrame::OnAngleDown
)
191 // Define my frame constructor
192 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
193 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
198 wxImage
image( wxT("test.jpg") );
201 for (i
= 0; i
< image
.GetWidth(); i
++)
202 for (j
= 0; j
< image
.GetHeight(); j
++)
203 image
.SetAlpha( i
, j
, 50 );
208 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
210 Close(true /*force closing*/);
213 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
215 wxPrintDialogData
printDialogData(* g_printData
);
217 wxPrinter
printer(& printDialogData
);
218 MyPrintout
printout(_T("My printout"));
219 if (!printer
.Print(this, &printout
, true /*prompt*/))
221 if (wxPrinter::GetLastError() == wxPRINTER_ERROR
)
222 wxMessageBox(_T("There was a problem printing.\nPerhaps your current printer is not set correctly?"), _T("Printing"), wxOK
);
224 wxMessageBox(_T("You canceled printing"), _T("Printing"), wxOK
);
228 (*g_printData
) = printer
.GetPrintDialogData().GetPrintData();
232 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
234 // Pass two printout objects: for preview, and possible printing.
235 wxPrintDialogData
printDialogData(* g_printData
);
236 wxPrintPreview
*preview
= new wxPrintPreview(new MyPrintout
, new MyPrintout
, & printDialogData
);
240 wxMessageBox(_T("There was a problem previewing.\nPerhaps your current printer is not set correctly?"), _T("Previewing"), wxOK
);
244 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
245 frame
->Centre(wxBOTH
);
250 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
252 (*g_pageSetupData
) = *g_printData
;
254 wxPageSetupDialog
pageSetupDialog(this, g_pageSetupData
);
255 pageSetupDialog
.ShowModal();
257 (*g_printData
) = pageSetupDialog
.GetPageSetupDialogData().GetPrintData();
258 (*g_pageSetupData
) = pageSetupDialog
.GetPageSetupDialogData();
261 #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
262 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
264 wxPostScriptPrinter
printer(g_printData
);
265 MyPrintout
printout(_T("My printout"));
266 printer
.Print(this, &printout
, true/*prompt*/);
268 (*g_printData
) = printer
.GetPrintData();
271 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
273 // Pass two printout objects: for preview, and possible printing.
274 wxPrintDialogData
printDialogData(* g_printData
);
275 wxPrintPreview
*preview
= new wxPrintPreview(new MyPrintout
, new MyPrintout
, & printDialogData
);
276 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
277 frame
->Centre(wxBOTH
);
282 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
284 (*g_pageSetupData
) = * g_printData
;
286 wxGenericPageSetupDialog
pageSetupDialog(this, g_pageSetupData
);
287 pageSetupDialog
.ShowModal();
289 (*g_printData
) = pageSetupDialog
.GetPageSetupDialogData().GetPrintData();
290 (*g_pageSetupData
) = pageSetupDialog
.GetPageSetupDialogData();
296 void MyFrame::OnPageMargins(wxCommandEvent
& WXUNUSED(event
))
298 (*g_pageSetupData
) = *g_printData
;
300 wxMacPageMarginsDialog
pageMarginsDialog(this, g_pageSetupData
);
301 pageMarginsDialog
.ShowModal();
303 (*g_printData
) = pageMarginsDialog
.GetPageSetupDialogData().GetPrintData();
304 (*g_pageSetupData
) = pageMarginsDialog
.GetPageSetupDialogData();
309 void MyFrame::OnPrintAbout(wxCommandEvent
& WXUNUSED(event
))
311 (void)wxMessageBox(_T("wxWidgets printing demo\nAuthor: Julian Smart"),
312 _T("About wxWidgets printing demo"), wxOK
|wxCENTRE
);
315 void MyFrame::OnAngleUp(wxCommandEvent
& WXUNUSED(event
))
321 void MyFrame::OnAngleDown(wxCommandEvent
& WXUNUSED(event
))
327 void MyFrame::Draw(wxDC
& dc
)
329 // This routine just draws a bunch of random stuff on the screen so that we
330 // can check that different types of object are being drawn consistently
331 // between the screen image, the print preview image (at various zoom
332 // levels), and the printed page.
333 dc
.SetBackground(*wxWHITE_BRUSH
);
335 dc
.SetFont(wxGetApp().m_testFont
);
337 // dc.SetBackgroundMode(wxTRANSPARENT);
339 dc
.SetPen(*wxBLACK_PEN
);
340 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
341 dc
.DrawRectangle(0, 0, 230, 350);
342 dc
.DrawLine(0, 0, 229, 349);
343 dc
.DrawLine(229, 0, 0, 349);
344 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
346 dc
.SetBrush(*wxCYAN_BRUSH
);
347 dc
.SetPen(*wxRED_PEN
);
349 dc
.DrawRoundedRectangle(0, 20, 200, 80, 20);
351 dc
.DrawText( wxT("Rectangle 200 by 80"), 40, 40);
353 dc
.SetPen( wxPen(*wxBLACK
,0,wxDOT_DASH
) );
354 dc
.DrawEllipse(50, 140, 100, 50);
355 dc
.SetPen(*wxRED_PEN
);
357 dc
.DrawText( wxT("Test message: this is in 10 point text"), 10, 180);
360 char *test
= "Hebrew שלום -- Japanese (日本語)";
361 wxString tmp
= wxConvUTF8
.cMB2WC( test
);
362 dc
.DrawText( tmp
, 10, 200 );
376 dc
.DrawPolygon( 5, points
, 20, 250, wxODDEVEN_RULE
);
377 dc
.DrawPolygon( 5, points
, 50, 250, wxWINDING_RULE
);
379 dc
.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 );
389 dc
.DrawSpline( 4, points
);
391 dc
.DrawArc( 20,10, 10,10, 25,40 );
395 str
.Printf( wxT("---- Text at angle %d ----"), i
);
396 dc
.DrawRotatedText( str
, 100, 300, i
);
399 str
.Printf( wxT("---- Text at angle %d ----"), i
);
400 dc
.DrawRotatedText( str
, 100, 300, i
);
402 wxIcon my_icon
= wxICON(mondrian
) ;
404 dc
.DrawIcon( my_icon
, 100, 100);
407 dc
.DrawBitmap( m_bitmap
, 10, 10 );
410 void MyFrame::OnSize(wxSizeEvent
& event
)
412 wxFrame::OnSize(event
);
415 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
416 EVT_MOUSE_EVENTS(MyCanvas::OnEvent
)
419 MyCanvas::MyCanvas(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
, long style
):
420 wxScrolledWindow(frame
, wxID_ANY
, pos
, size
, style
)
422 SetBackgroundColour(* wxWHITE
);
425 void MyCanvas::OnDraw(wxDC
& dc
)
430 void MyCanvas::OnEvent(wxMouseEvent
& WXUNUSED(event
))
434 bool MyPrintout::OnPrintPage(int page
)
444 // Draw page numbers at top left corner of printable area, sized so that
445 // screen size of text matches paper size.
446 MapScreenSizeToPage();
448 wxSprintf(buf
, wxT("PAGE %d"), page
);
449 dc
->DrawText(buf
, 0, 0);
457 bool MyPrintout::OnBeginDocument(int startPage
, int endPage
)
459 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
465 void MyPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
473 bool MyPrintout::HasPage(int pageNum
)
475 return (pageNum
== 1 || pageNum
== 2);
478 void MyPrintout::DrawPageOne()
480 // You might use THIS code if you were scaling graphics of known size to fit
481 // on the page. The commented-out code illustrates different ways of scaling
484 // We know the graphic is 230x350. If we didn't know this, we'd need to
489 // This sets the user scale and origin of the DC so that the image fits
490 // within the paper rectangle (but the edges could be cut off by printers
491 // that can't print to the edges of the paper -- which is most of them. Use
492 // this if your image already has its own margins.
493 // FitThisSizeToPaper(wxSize(maxX, maxY));
494 // wxRect fitRect = GetLogicalPaperRect();
496 // This sets the user scale and origin of the DC so that the image fits
497 // within the page rectangle, which is the printable area on Mac and MSW
498 // and is the entire page on other platforms.
499 // FitThisSizeToPage(wxSize(maxX, maxY));
500 // wxRect fitRect = GetLogicalPageRect();
502 // This sets the user scale and origin of the DC so that the image fits
503 // within the page margins as specified by g_PageSetupData, which you can
504 // change (on some platforms, at least) in the Page Setup dialog. Note that
505 // on Mac, the native Page Setup dialog doesn't let you change the margins
506 // of a wxPageSetupDialogData object, so you'll have to write your own dialog or
507 // use the Mac-only wxMacPageMarginsDialog, as we do in this program.
508 FitThisSizeToPageMargins(wxSize(maxX
, maxY
), *g_pageSetupData
);
509 wxRect fitRect
= GetLogicalPageMarginsRect(*g_pageSetupData
);
511 // This sets the user scale and origin of the DC so that the image appears
512 // on the paper at the same size that it appears on screen (i.e., 10-point
513 // type on screen is 10-point on the printed page) and is positioned in the
514 // top left corner of the page rectangle (just as the screen image appears
515 // in the top left corner of the window).
516 // MapScreenSizeToPage();
517 // wxRect fitRect = GetLogicalPageRect();
519 // You could also map the screen image to the entire paper at the same size
520 // as it appears on screen.
521 // MapScreenSizeToPaper();
522 // wxRect fitRect = GetLogicalPaperRect();
524 // You might also wish to do you own scaling in order to draw objects at
525 // full native device resolution. In this case, you should do the following.
526 // Note that you can use the GetLogicalXXXRect() commands to obtain the
527 // appropriate rect to scale to.
528 // MapScreenSizeToDevice();
529 // wxRect fitRect = GetLogicalPageRect();
531 // Each of the preceding Fit or Map routines positions the origin so that
532 // the drawn image is positioned at the top left corner of the reference
533 // rectangle. You can easily center or right- or bottom-justify the image as
536 // This offsets the image so that it is centered within the reference
537 // rectangle defined above.
538 wxCoord xoff
= (fitRect
.width
- maxX
) / 2;
539 wxCoord yoff
= (fitRect
.height
- maxY
) / 2;
540 OffsetLogicalOrigin(xoff
, yoff
);
542 // This offsets the image so that it is positioned at the bottom right of
543 // the reference rectangle defined above.
544 // wxCoord xoff = (fitRect.width - maxX);
545 // wxCoord yoff = (fitRect.height - maxY);
546 // OffsetLogicalOrigin(xoff, yoff);
548 frame
->Draw(*GetDC());
551 void MyPrintout::DrawPageTwo()
553 // You might use THIS code to set the printer DC to ROUGHLY reflect
554 // the screen text size. This page also draws lines of actual length
557 // Compare this to DrawPageOne(), which uses the really convenient routines
558 // from wxPrintout to fit the screen image onto the printed page. This page
559 // illustrates how to do all the scaling calculations yourself, if you're so
564 // Get the logical pixels per inch of screen and printer
565 int ppiScreenX
, ppiScreenY
;
566 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
567 int ppiPrinterX
, ppiPrinterY
;
568 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
570 // This scales the DC so that the printout roughly represents the the screen
571 // scaling. The text point size _should_ be the right size but in fact is
572 // too small for some reason. This is a detail that will need to be
573 // addressed at some point but can be fudged for the moment.
574 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
576 // Now we have to check in case our real page size is reduced (e.g. because
577 // we're drawing to a print preview memory DC)
578 int pageWidth
, pageHeight
;
581 GetPageSizePixels(&pageWidth
, &pageHeight
);
583 // If printer pageWidth == current DC width, then this doesn't change. But w
584 // might be the preview bitmap width, so scale down.
585 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
586 dc
->SetUserScale(overallScale
, overallScale
);
588 // Calculate conversion factor for converting millimetres into logical
589 // units. There are approx. 25.4 mm to the inch. There are ppi device units
590 // to the inch. Therefore 1 mm corresponds to ppi/25.4 device units. We also
591 // divide by the screen-to-printer scaling factor, because we need to
592 // unscale to pass logical units to DrawLine.
594 // Draw 50 mm by 50 mm L shape
595 float logUnitsFactor
= (float)(ppiPrinterX
/(scale
*25.4));
596 float logUnits
= (float)(50*logUnitsFactor
);
597 dc
->SetPen(* wxBLACK_PEN
);
598 dc
->DrawLine(50, 250, (long)(50.0 + logUnits
), 250);
599 dc
->DrawLine(50, 250, 50, (long)(250.0 + logUnits
));
601 dc
->SetBackgroundMode(wxTRANSPARENT
);
602 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
604 { // GetTextExtent demo:
605 wxString words
[7] = {_T("This "), _T("is "), _T("GetTextExtent "), _T("testing "), _T("string. "), _T("Enjoy "), _T("it!")};
607 long x
= 200, y
= 250;
608 wxFont
fnt(15, wxSWISS
, wxNORMAL
, wxNORMAL
);
612 for (int i
= 0; i
< 7; i
++)
614 wxString word
= words
[i
];
615 word
.Remove( word
.Len()-1, 1 );
616 dc
->GetTextExtent(word
, &w
, &h
);
617 dc
->DrawRectangle(x
, y
, w
, h
);
618 dc
->GetTextExtent(words
[i
], &w
, &h
);
619 dc
->DrawText(words
[i
], x
, y
);
625 dc
->SetFont(wxGetApp().m_testFont
);
627 dc
->DrawText(_T("Some test text"), 200, 300 );
632 int rightMargin
= 20;
634 int bottomMargin
= 20;
636 int pageWidthMM
, pageHeightMM
;
637 GetPageSizeMM(&pageWidthMM
, &pageHeightMM
);
639 float leftMarginLogical
= (float)(logUnitsFactor
*leftMargin
);
640 float topMarginLogical
= (float)(logUnitsFactor
*topMargin
);
641 float bottomMarginLogical
= (float)(logUnitsFactor
*(pageHeightMM
- bottomMargin
));
642 float rightMarginLogical
= (float)(logUnitsFactor
*(pageWidthMM
- rightMargin
));
644 dc
->SetPen(* wxRED_PEN
);
645 dc
->DrawLine( (long)leftMarginLogical
, (long)topMarginLogical
,
646 (long)rightMarginLogical
, (long)topMarginLogical
);
647 dc
->DrawLine( (long)leftMarginLogical
, (long)bottomMarginLogical
,
648 (long)rightMarginLogical
, (long)bottomMarginLogical
);
650 WritePageHeader(this, dc
, _T("A header"), logUnitsFactor
);
653 // Writes a header on a page. Margin units are in millimetres.
654 bool WritePageHeader(wxPrintout
*printout
, wxDC
*dc
, const wxChar
*text
, float mmToLogical
)
657 static wxFont *headerFont = (wxFont *) NULL;
660 headerFont = wxTheFontList->FindOrCreateFont(16, wxSWISS, wxNORMAL, wxBOLD);
662 dc->SetFont(headerFont);
665 int pageWidthMM
, pageHeightMM
;
667 printout
->GetPageSizeMM(&pageWidthMM
, &pageHeightMM
);
668 wxUnusedVar(pageHeightMM
);
672 int rightMargin
= 10;
674 float leftMarginLogical
= (float)(mmToLogical
*leftMargin
);
675 float topMarginLogical
= (float)(mmToLogical
*topMargin
);
676 float rightMarginLogical
= (float)(mmToLogical
*(pageWidthMM
- rightMargin
));
678 wxCoord xExtent
, yExtent
;
679 dc
->GetTextExtent(text
, &xExtent
, &yExtent
);
680 float xPos
= (float)(((((pageWidthMM
- leftMargin
- rightMargin
)/2.0)+leftMargin
)*mmToLogical
) - (xExtent
/2.0));
681 dc
->DrawText(text
, (long)xPos
, (long)topMarginLogical
);
683 dc
->SetPen(* wxBLACK_PEN
);
684 dc
->DrawLine( (long)leftMarginLogical
, (long)(topMarginLogical
+yExtent
),
685 (long)rightMarginLogical
, (long)topMarginLogical
+yExtent
);