CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    110

    Challenging Print Preview Problem

    Hi,

    I am trying to develop a print preview function for my MFC application. Below is a brief account of how I go about doing it...or rather how it was done previously (I had to do code reuse from previous developer!)

    Step 1) Executed in CMainFrame
    CWinApp::OnFileNew();

    A call to this function. I am not sure why this step is needed.
    Supposedly, from the comments, it is to create a Print View?
    ----------------------------------------------------------------------------

    Step 2) Executed in CMainFrame
    The following codes are executed
    I belief this is to find the main View Class when a project is created using the MFC wizard. Note, the found CView is stored in
    m_pTestView

    CView* pView;
    CTestView *m_pTestView; // A ptr to application's main view obj
    CMDIChildWnd* pMDIActive;
    CDocument* pDoc;
    POSITION pos;

    pMDIActive= MDIGetActive();
    ASSERT(pMDIActive);

    // CDocument
    pDoc= pMDIActive->GetActiveDocument();
    ASSERT(pDoc);
    ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CTestDoc)));

    // GetNextView POSITION
    pos= pDoc->GetFirstViewPosition();
    while(pos!= NULL)
    {
    pView= pDoc->GetNextView(pos);
    if(pView->IsKindOf(RUNTIME_CLASS(CTestView)))
    m_pTestView = pView;
    }
    ASSERT(0);
    return 0;
    ----------------------------------------------------------------------------

    Step 3) Executed in CMainFrame
    ASSERT(pView);
    ----------------------------------------------------------------------------

    Step 4) Executed in CMainFrame
    m_pTestView->ExePrintPreview()

    The above function is defined in CTestView and it only execute one line of code:

    CView::OnFilePrintPreview()
    ----------------------------------------------------------------------------


    That's it. 4 Steps and the Print Preview is created and displayed. However, there are some problems.

    1) When Step 1 is executed (CWinApp::OnFileNew()), a dialog appears. Refer to picture below. How can I not show this dialog?
    Also, if i click on cancel, the program will crash

    2) In the print preview mode, when I press "Ctrl-Alt-Del" or clicking the top right close button, it will send a message similar to that when I close my application. As in it thinks that I am closing the application!? After that, it just close the Print preview and resumes control back to my main application

    3) In Print Preview mode, if i right click on the icon in the task bar, the program will also crash.

    Any help is greatly appreciated

    Desmond
    Attached Images Attached Images  

  2. #2
    Join Date
    Apr 2001
    Location
    Karachi, Pakistan.
    Posts
    466
    Hi,

    1) are you displaying that dialog box yourself? or its just appearing from no-where? If you are displaying it... and you dont wona show it... then you may HIDE it? And if its appearing from somwhere you dont know... then i guess you need debug.

    2) As you press Ctrl+Alt+Del the application receives the messages of OnDraw(and i guess... OnSize too). So there might be something written in your OnDraw function. You shud comments those lines... and then build the application again and run.
    KMan
    use code-tags
    Rating a post is'nt injurious(0:


    http://izlooite.blogspot.com

  3. #3
    Join Date
    Oct 2003
    Posts
    110
    The dialog appears because of the CWinApp::OnFileNew() function.

    Inside this function, it calls another function
    m_pDocManager->OnFileNew();

    Inside this OnFileNew function, it creates a CNewTypeDlg dialog and calls its DoModal function. Thats when the dialog appears. But my previous developers used the same code and the dialog did not appear. It simple executes pass the DoModal function.

    Any ideas?

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    Print preview is a standard feature of MFC. If you want to add it, why are you trying to do it on a new empty document (thats what OnFIleNew() does). You can probably skip that stage. You probably only need to add a menu option for ID_FILE_PRINT_PREVIEW to your menu. If its not a dialog app, that will get the basics working, and all you need to do is mess around with your OnPreparePrinting() and OnPrint() functions for your documents view.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  5. #5
    Join Date
    Oct 2003
    Posts
    110
    i agree. I would have done what you said. But the thing is i'm maintaining legacy codes. Or rather I have to follow. The schedule Im following doesn't allow me to start a project anew.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured