PrintPreview in MFC SDI Application
-
Hi, I am facing problem in my project and to simulate this problem I have reproduced in sample application. I have created a SDI MFC app with doc view architecture. I am facing problem while Print preview. While I close the preview Window, application hangs and after some time it crashed. Following is the implementation of OnFilePrintPreview and OnEndPrintPreview: void CSampleView::OnFilePrintPreview() { // must not create this on the frame. Must outlive this function CPrintPreviewState* pState = new CPrintPreviewState; // temporary remove the parent so that the DoPrintPreview() uses the mainframe ShowWindow(SW_HIDE); SetParent(NULL); //AfxMessageBox("Before DoPrintPreview"); if (!DoPrintPreview(AFX_IDD_PREVIEW_TOOLBAR, this, RUNTIME_CLASS(CPreviewView), pState)) { //AfxMessageBox("After DoPrintPreview IF"); // In derived classes, reverse special window handling here for // Preview failure case TRACE0("Error: DoPrintPreview failed.\n"); AfxMessageBox(AFX_IDP_COMMAND_FAILURE); delete pState; // preview failed to initialize, delete State now } //AfxMessageBox("After DoPrintPreview"); } void CSampleView::OnEndPrintPreview( CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView) { pView->DestroyWindow(); SetParent(AfxGetApp()->m_pMainWnd); AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW); AfxGetApp()->m_pMainWnd->UpdateWindow(); } Please provide input on this if anybody has any idea on this. Thanks in Advance!! Regards, Tony
-
Hi, I am facing problem in my project and to simulate this problem I have reproduced in sample application. I have created a SDI MFC app with doc view architecture. I am facing problem while Print preview. While I close the preview Window, application hangs and after some time it crashed. Following is the implementation of OnFilePrintPreview and OnEndPrintPreview: void CSampleView::OnFilePrintPreview() { // must not create this on the frame. Must outlive this function CPrintPreviewState* pState = new CPrintPreviewState; // temporary remove the parent so that the DoPrintPreview() uses the mainframe ShowWindow(SW_HIDE); SetParent(NULL); //AfxMessageBox("Before DoPrintPreview"); if (!DoPrintPreview(AFX_IDD_PREVIEW_TOOLBAR, this, RUNTIME_CLASS(CPreviewView), pState)) { //AfxMessageBox("After DoPrintPreview IF"); // In derived classes, reverse special window handling here for // Preview failure case TRACE0("Error: DoPrintPreview failed.\n"); AfxMessageBox(AFX_IDP_COMMAND_FAILURE); delete pState; // preview failed to initialize, delete State now } //AfxMessageBox("After DoPrintPreview"); } void CSampleView::OnEndPrintPreview( CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView) { pView->DestroyWindow(); SetParent(AfxGetApp()->m_pMainWnd); AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW); AfxGetApp()->m_pMainWnd->UpdateWindow(); } Please provide input on this if anybody has any idea on this. Thanks in Advance!! Regards, Tony
Had this problem before. Dont remember exactly how I solved. I think that, OnEndPrintPreview, call: SetDlgCtrlID(AFX_IDW_PANE_FIRST); I have an article, http://www.codeproject.com/KB/miscctrl/BasicAdminCP.aspx In the utils folder, ViewPrintPreview.cpp there is code working.
it´s the journey, not the destination that matters
-
Had this problem before. Dont remember exactly how I solved. I think that, OnEndPrintPreview, call: SetDlgCtrlID(AFX_IDW_PANE_FIRST); I have an article, http://www.codeproject.com/KB/miscctrl/BasicAdminCP.aspx In the utils folder, ViewPrintPreview.cpp there is code working.
it´s the journey, not the destination that matters
-
Thanks for your response. It helped me partailly but I guess now I can solve that. Once again thank you for your response! Regards, Tony
You´re welcome. I spent a LOT of time making print preview work for different controls and situations.
it´s the journey, not the destination that matters