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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ? Strange print behaviour

? Strange print behaviour

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpquestion
1 Posts 1 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.
  • R Offline
    R Offline
    Richard Ellis
    wrote on last edited by
    #1

    Firstly thanks to all who maintain and contribute to this site. I have learnt a lot from your efforts, so thanks again. Now to my problem. I have an application that is required to print some reports. I have done this by deriving a view from CView and using the MFC framework to do the printing for me. I have overwritten OnPreparePrinting, OnPrepareDC, OnBeginPrinting etc. Now everything has been working fine for quite a while now. Yesterday I came to do some minor modifications to the format of the report. I recompiled my application in debug and stepped into my code. I got an assertion failure in ...\mfc\src\viewprnt.cpp. It occurs in the function DoPreparePrinting(). pInfo has been created using default values etc - I don't try and do anything with it. I won't copy all the code for the function in here but basically it is an if..else statement. My code executes the else statement and I have marked the bit that fails. else { // otherwise, bring up the print dialog and allow user to change things // preset From-To range same as Min-Max range pInfo->m_pPD->m_pd.nFromPage = (WORD)pInfo->GetMinPage(); pInfo->m_pPD->m_pd.nToPage = (WORD)pInfo->GetMaxPage(); if (pApp->DoPrintDialog(pInfo->m_pPD) != IDOK) return FALSE; // do not print } ASSERT(pInfo->m_pPD != NULL); ***** ASSERT(pInfo->m_pPD->m_pd.hDC != NULL); **** This fails if (pInfo->m_pPD->m_pd.hDC == NULL) return FALSE; Now the things that bother me are that it worked in the past but not now. I have not changed the code that produces the report - only a small cosmetic change the the layout of the report. And further if I execute the program rather than step into it it works! I have done my best to wade through the documentation hand have searched the MSDN site and read the references I could find. I have stepped through this repeatedly and am most puzzled. From looking at the code in CView I can see that pInfo->m_pPD->m_pd.hDC seems to be created when CreatePrinterDC is called. However as I step through that statement is never called - it is in branches of code that my application doesn't execute. I don't really want to change what the user sees because I do want them to be able to change the default printer used. I have tried cutting and pasting CView's DoPreparePrinting function and inserting a CreatePrinterDC call but all this leads to is a crash when CView later on calls GetPortName because the pointer returned by ::GlobalLock(hDevnames) is NULL. If anyone has any ideas as to what might have happened

    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