Click here to Skip to main content
15,894,410 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Printer Control Pin
Richard MacCutchan28-Aug-16 20:56
mveRichard MacCutchan28-Aug-16 20:56 
GeneralRe: Printer Control Pin
Jochen Arndt28-Aug-16 21:38
professionalJochen Arndt28-Aug-16 21:38 
GeneralRe: Printer Control Pin
Richard MacCutchan28-Aug-16 22:03
mveRichard MacCutchan28-Aug-16 22:03 
GeneralRe: Printer Control Pin
Jochen Arndt28-Aug-16 22:09
professionalJochen Arndt28-Aug-16 22:09 
GeneralRe: Printer Control Pin
Richard MacCutchan28-Aug-16 22:19
mveRichard MacCutchan28-Aug-16 22:19 
GeneralRe: Printer Control Pin
Bram van Kampen1-Sep-16 13:37
Bram van Kampen1-Sep-16 13:37 
GeneralRe: Printer Control Pin
Richard MacCutchan1-Sep-16 23:37
mveRichard MacCutchan1-Sep-16 23:37 
GeneralRe: Printer Control Pin
Bram van Kampen4-Sep-16 15:24
Bram van Kampen4-Sep-16 15:24 
Well,

The Binary I get refuses to open.

Here is my Printing Code:-
C++
///////////////////////////////////////////////////////////////////////////////////
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
//
// PRINTING!!
///////////////////////////////////////////////////////////////////////////////////

// OnClick the Print Button
void CConfirmOrdersStep1Dlg::OnPrint() 
{
    if(CreateViewForPrinting()==false){
        AfxMessageBox("No Orders have been Marked for Printing");
        return;
    }
    CDC dc;
    CPrintDialog printDlg(FALSE);

<pre>
if (printDlg.DoModal() == IDCANCEL)     // Get printer settings from user
    return;

dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
dc.m_bPrinting = TRUE;

CString strTitle="Old Orders";                       // Get the application title
//strTitle.LoadString(AFX_IDS_APP_TITLE);

// strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);
DOCINFO di;                             // Initialise print document details
memset(&di, 0,sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;

BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job

// Get the printing extents and store in the m_rectDraw field of a 
// CPrintInfo object
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0, 
                        dc.GetDeviceCaps(HORZRES), 
                        dc.GetDeviceCaps(VERTRES));

OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function

// Now, Print every Page!
UINT page;
for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){

    dc.StartPage();                     // begin new page
    Info.m_nCurPage = page;
    PrintPage(&dc, &Info);                // Call your "Print page" function
    bPrintingOK = (dc.EndPage() > 0);   // end page
}
OnEndPrinting(&dc, &Info);              // Call your "Clean up" function

if (bPrintingOK)
    dc.EndDoc();                        // end a print job
else
    dc.AbortDoc();                      // abort job.

dc.DeleteDC();                          // delete the printer DC    

}

// As from Chris Mauder.
// Instead of Global I made it a member
//
// m_pView (Type COrderPageView) contains a list of PageFragments
// The Fragment at index 0 is the header, to be printed at the Top
// of each Page (Customer Details, etc)
// CondensePages() does Nothing for Now.
//
// Anyways, This Works, as I can successfully print the Page to a Text
// File.

void CConfirmOrdersStep1Dlg::OnBeginPrinting(CDC * pDC, CPrintInfo * pInfo)
{
// Set the Font to "CourierNew"
CFont PrinterFont;
if(!PrinterFont.CreatePointFont( 
    100,                     //int nPointSize*10, 
    "Courier New",      //LPCTSTR lpszFaceName, 
    pDC)){              //CDC* pDC = NULL 
    ASSERT(NULL);
    return;
}

// Here we have m_pPageList, a poiner to a CPageList Object
// the First Entry is a Header, detailing the Customer,
// The Next Entries contain Order Bodies, complete with
// Totals and Check Boxes!
// We can find out how high each Line Rectangle is.
CSize Size=pDC->GetTextExtent("AAAA",4);

// We Print 40 Wide in a Fixed Pitch Font!
m_nCurrentPrintRectWidth=Size.cx*10;

m_nCurrentLineHeight=Size.cy;

// We know the size of the Print Rectangle, so, we can
// Calculate the number of Lines per Page.

int PageHeight=pInfo->m_rectDraw.Height();
m_nLinesPerPage=PageHeight/m_nCurrentLineHeight;

// Next, we calculate the Number of Pages required, taking
// into Consideration, that Each Page accomodates the Header 
// Page, and a One Line Footer: Page %i of %i.
// We Modify m_pPageList, so that Each Entry, Except the First
// (Header) entry, represents a Printable Page!

// We try to fit as many orders as possible on a single print page.
// we Need to do a Lorry Loading Calculation.

m_pView->CondensePages(m_nLinesPerPage);

}

/////////////////////////////////////////////////////////////////
//
// This is where we print, First the Header, and thereafter the Page Content

void CConfirmOrdersStep1Dlg::PrintPage(CDC * pDC, CPrintInfo * pInfo)
{
int PageNumber=pInfo->m_nCurPage;
m_nCurrentPrintRectTop=0;
COrderPageView* pView=(COrderPageView*)m_pView->GetDataFromIndex(0);
PrintDocFragment(pView,pDC);
COrderPageView* pOrder=(COrderPageView*)m_pView->GetDataFromIndex(PageNumber);
PrintDocFragment(pOrder,pDC);

}

void CConfirmOrdersStep1Dlg::OnEndPrinting(CDC * pDC, CPrintInfo * pInfo)
{
// Do as Little as Possibe Here
// We have to de-select the CFont object, and delete it.

}

// We Create a List of Set of lists of 40 char wide strings
// The First Item in this List is the Header, specifying the
// Customer Details
// The remaining items contain Order Details for the Same Customer
// This Part Works, As is shown by 'DumpToTextFile()'

bool CConfirmOrdersStep1Dlg::CreateViewForPrinting()
{
delete m_pView;
m_pView=new COrderPageList();
int i;
int ItemCount=0;
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)="=1)ItemCount++;
" }
="" if(itemcount="=0)return" false;
="" tag_str_customer*="" pcust="m_pNode-">pCustomer;
COrderPageView* pPageHeader=new COrderPageView(NULL,40);
pPageHeader->m_pCustomer=m_pNode->pCustomer;
pPageHeader->PrintPageHeader();
m_pView->AddReference(pPageHeader);
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)!="1)continue;
" int="" index="((int)m_cList.GetItemData(i))-BIAS;
" lpstr_order="" po="(LPSTR_ORDER)m_pOrderList-">GetDataFromIndex(Index);
COrderPageView* pPageView=new COrderPageView(pO,40);
pPageView->PrintOrderBody();
m_pView->AddReference(pPageView);
}

ifdef _DEBUG

m_pView->DumpToTextFile();

endif

return true;

}

///////////////////////////////////////////////////////////////////////////////
//
// THIS IS WHERE THE RUBBER MEETS THE ROAD!
//
// We Are Committing a Set of Lines of Text in an Incrementing
// List of adjusting Rectangles.

int CConfirmOrdersStep1Dlg::PrintDocFragment(COrderPageView * pView, CDC * pDC)
{
ASSERT(pView);
ASSERT(pDC);
int i;
for(i=0;i<pview->GetItemCount();i++){
RECT DrawingRect;
DrawingRect.left=0;
DrawingRect.top=m_nCurrentPrintRectTop;
m_nCurrentPrintRectTop+=m_nCurrentLineHeight;
DrawingRect.right=m_nCurrentPrintRectWidth;
DrawingRect.bottom=m_nCurrentPrintRectTop-1;

LPCSTR DrawingText=(LPCSTR)pView->GetDataFromIndex(i);
pDC->DrawText(DrawingText,-1,&DrawingRect,DT_LEFT);

}
return i;
}
Getting Desparate at this stage. I Guess I am doing something trivial wrong.

Thanks + Regards,

Smile | :)
Bram van Kampen

GeneralRe: Printer Control Pin
Bram van Kampen4-Sep-16 15:30
Bram van Kampen4-Sep-16 15:30 
GeneralRe: Printer Control Pin
Richard MacCutchan4-Sep-16 21:39
mveRichard MacCutchan4-Sep-16 21:39 
GeneralRe: Printer Control Pin
Bram van Kampen6-Sep-16 16:03
Bram van Kampen6-Sep-16 16:03 
GeneralRe: Printer Control Pin
Richard MacCutchan6-Sep-16 21:35
mveRichard MacCutchan6-Sep-16 21:35 
GeneralRe: Printer Control Pin
Bram van Kampen8-Sep-16 14:18
Bram van Kampen8-Sep-16 14:18 
GeneralRe: Printer Control Pin
Richard MacCutchan8-Sep-16 22:37
mveRichard MacCutchan8-Sep-16 22:37 
GeneralRe: Printer Control Pin
Richard MacCutchan4-Sep-16 22:40
mveRichard MacCutchan4-Sep-16 22:40 
QuestionCustom Slider control messages cannot be caught Pin
AlbertB25-Aug-16 2:54
AlbertB25-Aug-16 2:54 
AnswerRe: Custom Slider control messages cannot be caught Pin
Richard MacCutchan25-Aug-16 3:47
mveRichard MacCutchan25-Aug-16 3:47 
GeneralRe: Custom Slider control messages cannot be caught Pin
AlbertB25-Aug-16 4:39
AlbertB25-Aug-16 4:39 
GeneralRe: Custom Slider control messages cannot be caught Pin
Richard MacCutchan25-Aug-16 4:59
mveRichard MacCutchan25-Aug-16 4:59 
GeneralRe: Custom Slider control messages cannot be caught Pin
AlbertB25-Aug-16 5:54
AlbertB25-Aug-16 5:54 
GeneralRe: Custom Slider control messages cannot be caught Pin
Bram van Kampen27-Aug-16 16:23
Bram van Kampen27-Aug-16 16:23 
GeneralRe: Custom Slider control messages cannot be caught Pin
AlbertB27-Aug-16 17:30
AlbertB27-Aug-16 17:30 
GeneralRe: Custom Slider control messages cannot be caught Pin
leon de boer28-Aug-16 22:27
leon de boer28-Aug-16 22:27 
GeneralRe: Custom Slider control messages cannot be caught Pin
AlbertB29-Aug-16 3:17
AlbertB29-Aug-16 3:17 
GeneralRe: Custom Slider control messages cannot be caught Pin
leon de boer29-Aug-16 5:34
leon de boer29-Aug-16 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.