The docomentation says:
wxDC* wxPrintout::GetDC ( ) const: "Returns the device context associated with the printout (given to the printout at start of printing or previewing)."
So how do I do that? The printer sample code doesn't have a single instance of wxPrinterDC.
Rob.
wxPrintout(): Where does the wxPrinterDC come from?
Re: wxPrintout(): Where does the wxPrinterDC come from?
The printer sample just uses a wxDC.
Code: Select all
bool MyPrintout::OnPrintPage(int page)
{
wxDC *dc = GetDC();
if (dc)
{
if (page == 1)
DrawPageOne();
else if (page == 2)
DrawPageTwo();
// Draw page numbers at top left corner of printable area, sized so that
// screen size of text matches paper size.
MapScreenSizeToPage();
dc->DrawText(wxString::Format(wxT("PAGE %d"), page), 0, 0);
return true;
}
else
return false;
}
Use the source, Luke!
Re: wxPrintout(): Where does the wxPrinterDC come from?
That could actually be anything derived from wxDC. Somewhere in the docs or sample it does actually say it's a wxPrinterDC or wxMemoryDC depending on whether it's a print or a print preview. I'm still unsure where it comes from though. A DC must somehow be associated with the device but how does that happen?
Rob.
Rob.
Re: wxPrintout(): Where does the wxPrinterDC come from?
I don't know the exact internals, but based on the following piece of code, the "printer specific" part comes from wxPrinter in combination with the wxPrintDialogData.
If you want to know more, just trace through this piece of code and see where it takes you
However, the whole concept is based on the idea that you use the same code for drawing on the screen and drawing to the printer. That's why the drawing method only takes a wxDC.
Code: Select all
void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
{
wxPrintDialogData printDialogData(* g_printData);
wxPrinter printer(&printDialogData);
MyPrintout printout(this, wxT("My printout"));
if (!printer.Print(this, &printout, true /*prompt*/))
However, the whole concept is based on the idea that you use the same code for drawing on the screen and drawing to the printer. That's why the drawing method only takes a wxDC.
Use the source, Luke!