PRINTDLG to CPrintInfo
-
Richard, is there a way to force printpreview to application, in such a way that user see nothing about it, just for retrieving CPrintInfo ? Could you tell me how ?
-
Richard, I still have a question: I had tried to create manually an CPrintInfo object, just like that:
CPrintDialog pdlg(FALSE); pdlg.GetDefaults(); HDC hDC = pdlg.CreatePrinterDC(); if(NULL != hDC) { m\_pPreviewInfo = new CPrintInfo; m\_dcPrint.CreateCompatibleDC(CDC::FromHandle(hDC)); m\_pPreviewInfo->m\_rectDraw.left = 0; m\_pPreviewInfo->m\_rectDraw.top = 0; m\_pPreviewInfo->m\_rectDraw.right = m\_dcPrint.GetDeviceCaps(HORZRES); m\_pPreviewInfo->m\_rectDraw.bottom = m\_dcPrint.GetDeviceCaps(VERTRES); m\_pPreviewInfo->m\_bContinuePrinting = TRUE; m\_pPreviewInfo->m\_bDirect = TRUE; m\_pPreviewInfo->m\_bDocObject = FALSE; m\_pPreviewInfo->m\_bPreview = TRUE; m\_pPreviewInfo->m\_lpUserData = NULL; m\_pPreviewInfo->m\_pPD = &pdlg; m\_pPreviewInfo->SetMinPage(1); m\_pPreviewInfo->SetMaxPage(2); m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages; m\_pPreviewDC = new CPreviewDC; m\_pPreviewDC->SetAttribDC(m\_pPreviewInfo->m\_pPD->m\_pd.hDC); m\_sizePrinterPPI.cx = m\_dcPrint.GetDeviceCaps(LOGPIXELSX); m\_sizePrinterPPI.cy = m\_dcPrint.GetDeviceCaps(LOGPIXELSY); m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages; if (m\_nPages == 0) m\_nPages = 1; else if (m\_nPages > m\_nMaxPages) m\_nPages = m\_nMaxPages; // Sanity Check! }
where m_pPreviewInfo and m_pPreviewDC is protected members of CMyCustomPrintPreview:
CPreviewDC\* m\_pPreviewDC; CPrintInfo\* m\_pPreviewInfo;
of the first sight, I had do something wrong on the above code ? Because when I am trying to use m_pPreviewInfo object in CMyCustomPrintPreview::OnDraw, is crashing and I get an access violation on:
_AFXEXT_INLINE UINT CPrintInfo::GetMaxPage() const
{ return m_pPD->m_pd.nMaxPage; }Thank you.
-
Richard, I still have a question: I had tried to create manually an CPrintInfo object, just like that:
CPrintDialog pdlg(FALSE); pdlg.GetDefaults(); HDC hDC = pdlg.CreatePrinterDC(); if(NULL != hDC) { m\_pPreviewInfo = new CPrintInfo; m\_dcPrint.CreateCompatibleDC(CDC::FromHandle(hDC)); m\_pPreviewInfo->m\_rectDraw.left = 0; m\_pPreviewInfo->m\_rectDraw.top = 0; m\_pPreviewInfo->m\_rectDraw.right = m\_dcPrint.GetDeviceCaps(HORZRES); m\_pPreviewInfo->m\_rectDraw.bottom = m\_dcPrint.GetDeviceCaps(VERTRES); m\_pPreviewInfo->m\_bContinuePrinting = TRUE; m\_pPreviewInfo->m\_bDirect = TRUE; m\_pPreviewInfo->m\_bDocObject = FALSE; m\_pPreviewInfo->m\_bPreview = TRUE; m\_pPreviewInfo->m\_lpUserData = NULL; m\_pPreviewInfo->m\_pPD = &pdlg; m\_pPreviewInfo->SetMinPage(1); m\_pPreviewInfo->SetMaxPage(2); m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages; m\_pPreviewDC = new CPreviewDC; m\_pPreviewDC->SetAttribDC(m\_pPreviewInfo->m\_pPD->m\_pd.hDC); m\_sizePrinterPPI.cx = m\_dcPrint.GetDeviceCaps(LOGPIXELSX); m\_sizePrinterPPI.cy = m\_dcPrint.GetDeviceCaps(LOGPIXELSY); m\_nPages = m\_pPreviewInfo->m\_nNumPreviewPages; if (m\_nPages == 0) m\_nPages = 1; else if (m\_nPages > m\_nMaxPages) m\_nPages = m\_nMaxPages; // Sanity Check! }
where m_pPreviewInfo and m_pPreviewDC is protected members of CMyCustomPrintPreview:
CPreviewDC\* m\_pPreviewDC; CPrintInfo\* m\_pPreviewInfo;
of the first sight, I had do something wrong on the above code ? Because when I am trying to use m_pPreviewInfo object in CMyCustomPrintPreview::OnDraw, is crashing and I get an access violation on:
_AFXEXT_INLINE UINT CPrintInfo::GetMaxPage() const
{ return m_pPD->m_pd.nMaxPage; }Thank you.
-
I suspect that your
CPrintDialog
object is going out of scope thus causing this error. You should usenew
to create it before adding it to yourCPrintInfo
. -
I suspect that your
CPrintDialog
object is going out of scope thus causing this error. You should usenew
to create it before adding it to yourCPrintInfo
. -
Yes, I had created dinamically (with new), but when I am trying to clean up in my class destructor, it crashing ...
CPrintPreview::~CPrintPreview
{
if(NULL != m_pPrintDlg)
delete m_pPrintDlg; // crash ! <----
}weird ...
-
It should be enough, but if it has somehow been corrupted, or already deleted then you will get a crash. The only way to check is via the debugger.