-
Re: BUG at Print ?!
Thanks
I have include
#include "afxprint.rc" // printing/print preview resources
into resources file and implement OnPreparePrinting() and OnPrint(), OnBeginPrinting() and OnEndPrinting()) in the view class, and call DoPreparePrinting() in the OnPreparePrinting() implementation.
I have included also into the resources file:
(accelerator)
"P", ID_FILE_PRINT, VIRTKEY,CONTROL
(into string table)
ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup"
ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup"
ID_FILE_PRINT "Print the active document\nPrint"
ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview"
Code:
void CVisionCARView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
pInfo->SetMinPage(1);
pInfo->SetMaxPage(1);
//CListView::OnBeginPrinting(pDC, pInfo);
}
void CVisionCARView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
//CListView::OnEndPrinting(pDC, pInfo);
}
BOOL CVisionCARView::OnPreparePrinting(CPrintInfo* pInfo)
{
// TODO: call DoPreparePrinting to invoke the Print dialog box
if(tiparesteComanda)
{
pInfo->SetMinPage(1);
pInfo->m_bDirect = TRUE; //don't show the printer settings }
pInfo->m_strPageDesc = "Page %u\nPages %u-%u\n";
PRINTDLG pd;
pd = pInfo->m_pPD->m_pd;
pd.lStructSize=(DWORD)sizeof(PRINTDLG);
BOOL bRet = theApp.GetPrinterDeviceDefaults(&pd);
if(bRet)
{
// protect memory handle with ::GlobalLock and ::GlobalUnlock
DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(pd.hDevMode);
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
// set orientation
if(tiparesteComanda)
{
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
}
else
if((tipVedere == 1) || (tipVedere == 3))
{
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
}
else
if(tipVedere == 2)
{
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
}
else
{
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
}
::GlobalUnlock(pd.hDevMode);
}
return DoPreparePrinting(pInfo);
//return CListView::OnPreparePrinting(pInfo);
}
void CVisionCARView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CPen penBlack(0, 1, RGB(200, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
pDC->MoveTo(0 ,0);
pDC->LineTo(300, 300);
pDC->SelectObject(pOldPen);
//CListView::OnPrint(pDC, pInfo);
}
It working now. Thanks. :) :) :)