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

    Documens was'n printed out but could preview?

    I made a simple Single Doc-View application and let the VC++ to handle the printing job.
    when I select [Print] command from the menu , and select a printer to print out the document , nothing came out from the printer. but I can preview the document by select the buildin [print preview] command from the menu.
    what may cause this kind of problom?

    Thanks for any reply


    Jeff

  2. #2
    Join Date
    Jul 2004
    Posts
    23

    Re: Documens was'n printed out but could preview?

    I have found out the reason to cause this problom.
    Code:
    void CCBCView::OnDraw(CDC* pDC)
    {
        CCADIODoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        // TODO: add draw code for native data here
        drawsomething( pDC->m_hDC );
    }
    
    void void CCBCView::drawsomething(  HDC hdc )
    {
        CDC dc;
        dc.Attach( hdc );   // <<------ this cause error !!!!
        dc.TextOut( hdc , "PRINT TEST" , 10 );
    }
    Once I construct a new CDC , and attach to the original CDC's handle that pass into OnDraw function . This App display in right way on the screen, but cannot print out any more .

  3. #3
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: Documens was'n printed out but could preview?

    You probably need to call Detach() on the CDC object as by default CDC destructor is probbaly trying to delete teh DC, thus invalidating the print job in some way
    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.

  4. #4

    Re: Documens was'n printed out but could preview?

    I think you should also consider to change the param of method drawsomething( HDC hdc ) from HDC hdc to CDC *pDC.

    Jack

    ---------------------------------------------------------------------------------
    XD++ MFC/C++ Flow/Diagram Library (Full Visio 2003 Like,100% Source Code Kit) -- http://www.********.net

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Documens was'n printed out but could preview?

    Right. you always need to paint onto the DC passed to you by Windows as andytim has suggested.

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