Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PrintPreview in MFC SDI Application

PrintPreview in MFC SDI Application

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++architecture
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tony_Udz
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • T tony_Udz

      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

      E Offline
      E Offline
      ErnestoNet
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • E ErnestoNet

        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

        T Offline
        T Offline
        tony_Udz
        wrote on last edited by
        #3

        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

        E 1 Reply Last reply
        0
        • T tony_Udz

          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

          E Offline
          E Offline
          ErnestoNet
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups