Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the end, it is probably easier to draw what you want into the the printDC. However, with some care, you can use BLIT to copy what is displayed in your panel into the PrintDC without having to redraw everything.</p> <p>So, in your override of the wxPrintout::OnPrintPage you can write something like this:</p> <pre><code> wxClientDC frameDC( wxGetApp().GetTopWindow() ); GetDC()-&gt;StretchBlit(0,0,5000,5000, &amp;frameDC, 0, 0, 500,500 ); </code></pre> <p>This will copy everything displayed in your applications top level wondow into the printerDC.</p> <p>The snag is that the print preview window tends to obliterate your top level frame contents when it pops up. If you have a large monitor and a small application window you can arrange things so they do not overlap</p> <pre><code>void MyFrame::OnPrint(wxCommandEvent&amp; ) { wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this), new MyPrintout(this)); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(600, 100), // move preview window out of the way wxSize(500, 500)); //frame-&gt;Centre(wxBOTH); frame-&gt;Initialize(); frame-&gt;Show(true); </code></pre> <p>A better approach would be to BLIT the frame display into a memoryDC before popping up the print preview, then BLIT from the MemoryDC to the printerDC.</p> <p>Something along these lines:</p> <pre><code>void MyFrame::OnPrint(wxCommandEvent&amp; ) { // save the display before it is clobbered by the print preview static wxMemoryDC memDC; static wxBitmap bitmap(500,500); memDC.SelectObject( bitmap ); wxClientDC frameDC( wxGetApp().GetTopWindow() ); memDC.Blit(0,0,5000,5000, &amp;frameDC, 0, 0 ); wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(memDC), new MyPrintout(memDC)); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(600, 100), // move preview window out of the way wxSize(500, 500)); frame-&gt;Centre(wxBOTH); frame-&gt;Initialize(); frame-&gt;Show(true); } </code></pre> <p>and then</p> <pre><code>class MyPrintout : public wxPrintout { wxMemoryDC &amp; myMemDC; public: MyPrintout( wxMemoryDC &amp; memDC) : myMemDC( memDC ) { } bool OnPrintPage( int PageNum ) { // copy saved dispay to printer DC GetDC()-&gt;StretchBlit(0,0,5000,5000, &amp;myMemDC, 0, 0, 500,500 ); return true; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload