Ok, CGridCtrl are o rezolvare foarte simpla pentru printpreview: ascunde frame-ul principal, si creeaza unul noul:
Code: Select all
CFrameWnd* pOldFrame=(CFrameWnd*)AfxGetThread()->m_pMainWnd;
pOldFrame->ShowWindow(SW_HIDE); //added by eric
if(! m_pTemplate)
{
m_pTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
NULL,
RUNTIME_CLASS(CFrameWnd),
RUNTIME_CLASS(CViewPrintPreview));
AfxGetApp()->AddDocTemplate(m_pTemplate);
}
CFrameWnd* pFrameWnd = m_pTemplate->CreateNewFrame(NULL, NULL);
m_bPrintPreview = TRUE;
m_pTemplate->InitialUpdateFrame(pFrameWnd, NULL, FALSE);
CViewPrintPreview* pView = (CViewPrintPreview*)pFrameWnd->GetActiveView();
pView->m_pCtrl = this;
pView->m_pOldFrame = pOldFrame;
AfxGetApp()->m_pMainWnd = pFrameWnd;
pFrameWnd->SetWindowText(_T("Grid Print Preview"));
pFrameWnd->ShowWindow(SW_SHOWMAXIMIZED);
pView->OnFilePrintPreview();
Code: Select all
CFrameWnd* pOldFrame = (CFrameWnd*)AfxGetThread()->m_pMainWnd;
pOldFrame->ShowWindow(SW_HIDE); //added by eric
if(NULL == m_pTemplate)
{
m_pTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
NULL,
RUNTIME_CLASS(CRPPMainFrame),
RUNTIME_CLASS(CRPPLeftView));
AfxGetApp()->AddDocTemplate(m_pTemplate);
}
CRPPMainFrame* pFrameWnd = (CRPPMainFrame*)m_pTemplate->CreateNewFrame(NULL, NULL);
m_bPrintPreview = TRUE;
m_pTemplate->InitialUpdateFrame(pFrameWnd, NULL, FALSE);
CReportPrintPreview* pView = (CReportPrintPreview*)pFrameWnd->GetRightPane();
pView->m_pCtrl = this;
pView->m_pOldFrame = pOldFrame;
AfxGetApp()->m_pMainWnd = pFrameWnd;
pFrameWnd->SetWindowText(_T("Tree Print Preview"));
pFrameWnd->ShowWindow(SW_SHOWMAXIMIZED);
pView->OnFilePrintPreview();
Codul din CRPPMainFrame e de asemenea simplu:
Code: Select all
BOOL CRPPMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// create splitter window
if(! m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if(! m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRPPLeftView), CSize(100, 100), pContext) ||
! m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CReportPrintPreview), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
return TRUE;
}
Atasez si un mic demo, pentru exemplificare ...