最後に、必要なものを printDC に描画する方がおそらく簡単です。ただし、注意が必要な場合は、BLIT を使用して、すべてを再描画することなく、パネルに表示されているものを PrintDC にコピーできます。
したがって、wxPrintout::OnPrintPage のオーバーライドでは、次のように記述できます。
wxClientDC frameDC( wxGetApp().GetTopWindow() );
GetDC()->StretchBlit(0,0,5000,5000,
&frameDC, 0, 0, 500,500 );
これにより、アプリケーションの最上位ウィンドウに表示されるすべてが printerDC にコピーされます。
問題は、印刷プレビュー ウィンドウがポップアップしたときにトップ レベルのフレーム コンテンツを消去する傾向があることです。大きなモニターと小さなアプリケーション ウィンドウがある場合は、それらが重ならないように配置できます。
void MyFrame::OnPrint(wxCommandEvent& )
{
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->Centre(wxBOTH);
frame->Initialize();
frame->Show(true);
より良いアプローチは、印刷プレビューをポップアップ表示する前にフレーム表示を memoryDC に BLIT し、次に MemoryDC から printerDC に BLIT することです。
これらの行に沿ったもの:
void MyFrame::OnPrint(wxCommandEvent& )
{
// 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,
&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->Centre(wxBOTH);
frame->Initialize();
frame->Show(true);
}
その後
class MyPrintout : public wxPrintout
{
wxMemoryDC & myMemDC;
public:
MyPrintout( wxMemoryDC & memDC)
: myMemDC( memDC )
{
}
bool OnPrintPage( int PageNum )
{
// copy saved dispay to printer DC
GetDC()->StretchBlit(0,0,5000,5000,
&myMemDC, 0, 0, 500,500 );
return true;
}
};