CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    86

    It can not print and print preview!!

    see my code first.

    pDocTemplate = new CMultiDocTemplate(
    IDR_FINALTTYPE,
    RUNTIME_CLASS(CFinalTDoc), //base CDocument
    RUNTIME_CLASS(CChildFrame), //base CMDIChildWnd
    RUNTIME_CLASS(CFinalTView)); //CListView
    AddDocTemplate(pDocTemplate);

    m_pTemplateTxt = new CMultiDocTemplate(
    IDR_FINALTTYPE,
    RUNTIME_CLASS(CCdoc), //base CDocument
    RUNTIME_CLASS(CChildFrame), // base CMDIChildWnd
    RUNTIME_CLASS(CTextView)); //base CView

    m_pTemplateTab = new CMultiDocTemplate(
    IDR_FINALTTYPE,
    RUNTIME_CLASS(CFinalTDoc), //base CDocument
    RUNTIME_CLASS(CChildFrame), //base CMDIChildWnd
    RUNTIME_CLASS(CFinalTView)); //base CView


    i define two functions to create VIEW-DOCUMENT-FRAME
    structure

    CDocument* CMainFrame::CreateDocTxt()
    {
    CFinalTApp* myapp =(CFinalTApp* )AfxGetApp();
    CDocument* pDoc=(CDocument* )
    myapp->m_pTemplateTxt->OpenDocumentFile(NULL);
    return pDoc;
    }
    CDocument* CMainFrame::CreateDocTab()
    {
    CFinalTApp* myapp =(CFinalTApp* )AfxGetApp();
    CDocument* pDoc=(CDocument* )
    myapp->m_pTemplateTab->OpenDocumentFile(NULL);
    return pDoc;
    }

    I use just one menu IDR_FINALTTYPE.
    why the view i use "CreateDocTab()" to create has the print and print preview ,but the view i use CreateDocTxt() to create does not have?

    i have defined the follow functions in both view?

    CXXXView::OnDraw()
    void CXXXView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
    BOOL CXXXView::OnPreparePrinting(CPrintInfo* pInfo)
    void CXXXView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    void CXXXView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

  2. #2
    Join Date
    Mar 2004
    Posts
    86
    anyone??

  3. #3
    Join Date
    Mar 2004
    Posts
    86
    who can help me

  4. #4
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    I don't see where you have called AddDocTemplate() after you have declared your text template in InitInstance(). That may be the problem.

    Also, your member tab template looks exactly like the first pDocTemplate. Why have both?

    Steve

  5. #5
    Join Date
    Mar 2004
    Posts
    86
    Originally posted by sstofka
    I don't see where you have called AddDocTemplate() after you have declared your text template in InitInstance(). That may be the problem.

    Also, your member tab template looks exactly like the first pDocTemplate. Why have both?

    Steve
    I did not call AddDocTemplate() because I think it is useless to do so.To Add Document Templates to CDocManager,what is the use of CDocManager?

    By the way,I have take this problem out from my "big" project.

    help me ,sir!
    http://www.codeguru.com/forum/showth...hreadid=296641

  6. #6
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    If CTextView does not have OnFilePrint, and the other printing handlers and virtual functions, just copy them from CFinalTView, and change the code appropriately.

    If you't call AddDocTemplate() in your InitInstance on the the member template pointers, then the app will not delete memory for the pointers as the app closes, so remember to free memory in the app's ExitInstance()

    Steve

  7. #7
    Join Date
    Mar 2004
    Posts
    86
    Originally posted by sstofka
    If CTextView does not have OnFilePrint, and the other printing handlers and virtual functions, just copy them from CFinalTView, and change the code appropriately.

    If you't call AddDocTemplate() in your InitInstance on the the member template pointers, then the app will not delete memory for the pointers as the app closes, so remember to free memory in the app's ExitInstance()

    Steve

    I have tried.but i does not work.

    to see my code,please
    Attached Files Attached Files

  8. #8
    Join Date
    Mar 2004
    Posts
    86

  9. #9
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    I don't have WinRAR so I can't unzip it and I'm not going to download a program just to unzip one file. If you can .zip the files, fine.

    Steve

  10. #10
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    To Add Document Templates to CDocManager,what is the use of CDocManager?
    CDocManager handles the list of document templates, and they in turn handle the list of open documents/views. You do need to register your document types with it as without doing so, you break some of the standard functionality of MFC, such as CloseAllDocuments(), GetOpenDocumentCount(), SaveAllModified() etc.

    Lets say you have 3 documents open all of which are modified, if you hit the close app button, you will not be asked to save your work, and the mainframe may well try and close with open documents present.
    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.

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