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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printing to exact coordinates on paper or lottery tickets

Printing to exact coordinates on paper or lottery tickets

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 Posts 2 Posters 6 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.
  • I Offline
    I Offline
    inlandchris1
    wrote on last edited by
    #1

    How to? I know the basic printing functions and using the CPrintDialog plus PRINTDLG pd, a little sample that only prints a statement but shows what I am using:

    CPrintDialog dlg(FALSE, pd.Flags);
    
    if (dlg.DoModal() != IDOK)
    {
    	AfxMessageBox("Abort or Unknown Printer or Printer device error");
    	return;
    }
    pd.hDC = dlg.CreatePrinterDC();
    ASSERT(pd.hDC !=0);
    

    /////////////////////////////////////////////////////////////////////////////////////////

    	 CDC \* dc  = new CDC;
    
    	 dc = CDC::FromHandle(pd.hDC);   
    		// Get Height and Width of large character
    	int  cxPage = ::GetDeviceCaps (pd.hDC, HORZRES) ;
    	int  cyPage = ::GetDeviceCaps (pd.hDC, VERTRES) ;
    
    	sizePrn.cx = cxPage;
    	sizePrn.cy = cyPage;
    
    
    memset(&lf, 0, sizeof(lf));
    lf.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);//abs(lf.lfHeight)
    lf.lfWeight = FW\_BOLD;  //FW\_MEDIUM; //;    
    lf.lfPitchAndFamily = FIXED\_PITCH | FF\_MODERN;
    lf.lfQuality = PROOF\_QUALITY; //NEW
    lstrcpy(lf.lfFaceName, "Times New Roman");  //"Courier");
    VERIFY(font.CreateFontIndirect(&lf));
    
    dc->SetMapMode (MM\_ISOTROPIC) ;
    dc->SetWindowExt ( 1000, 1000) ;
    dc->SetViewportExt (cxPage / 2, -cyPage / 2) ;
    dc->SetViewportOrg (cxPage / 2,  cyPage / 2) ;
    dc->SetTextAlign(TA\_BASELINE | TA\_CENTER);
    dc->SetBkMode(OPAQUE);
    dc->SetMapMode(MM\_TEXT);
    dc->PatBlt(0, 0, sizePrn.cx, sizePrn.cy, WHITENESS);
    dc->LPtoDP(&sizePrn);
    dc->SelectObject(&font) ;
    
     CSize extentChar = dc ->GetTextExtent("M",1);
     int nCharHeight  = extentChar.cy+4;
     int nCharWidth	  = extentChar.cx+10;     
    

    // Begin printing the doc
    BeginWaitCursor();

    CString printDate = GetMyCurDateTime();
    
    DOCINFO docinfo;
    memset(&docinfo, 0, sizeof(docinfo));
    docinfo.cbSize = sizeof(docinfo);
    docinfo.lpszDocName = \_T("Calif Lottery Winnings");
    docinfo.fwType = 0;
    
    
    rc = dc->StartDocA(&docinfo);
    if (rc < 0)
    {
    	sprintf(temp, "Unable to Begin printing - Error\[%d\]", rc);
    	MessageBox(temp, NULL, MB\_OK);
    	dc->ReleaseAttribDC();
    	dc->ReleaseOutputDC();
    	dc->DeleteTempMap();
    	EndWaitCursor();
    	DeleteDC(pd.hDC);
    	if(pd.hDevMode != NULL)
    		GlobalFree(pd.hDevMode);
    	if(pd.hDevNames != NULL)
    		GlobalFree(pd.hDevNames);
    	dc = 0;
    	return;
    }
    szTitle=CString("California Lottery System Printout     ") + printDate;
    //Print a Page Header
    dc -> StartPage();
    dc -> SetTextAlign(TA\_LEFT | TA\_TOP);
    dc -> TextOut(0, 0, szTitle, szTitle.GetLength() );
    
    L 1 Reply Last reply
    0
    • I inlandchris1

      How to? I know the basic printing functions and using the CPrintDialog plus PRINTDLG pd, a little sample that only prints a statement but shows what I am using:

      CPrintDialog dlg(FALSE, pd.Flags);
      
      if (dlg.DoModal() != IDOK)
      {
      	AfxMessageBox("Abort or Unknown Printer or Printer device error");
      	return;
      }
      pd.hDC = dlg.CreatePrinterDC();
      ASSERT(pd.hDC !=0);
      

      /////////////////////////////////////////////////////////////////////////////////////////

      	 CDC \* dc  = new CDC;
      
      	 dc = CDC::FromHandle(pd.hDC);   
      		// Get Height and Width of large character
      	int  cxPage = ::GetDeviceCaps (pd.hDC, HORZRES) ;
      	int  cyPage = ::GetDeviceCaps (pd.hDC, VERTRES) ;
      
      	sizePrn.cx = cxPage;
      	sizePrn.cy = cyPage;
      
      
      memset(&lf, 0, sizeof(lf));
      lf.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);//abs(lf.lfHeight)
      lf.lfWeight = FW\_BOLD;  //FW\_MEDIUM; //;    
      lf.lfPitchAndFamily = FIXED\_PITCH | FF\_MODERN;
      lf.lfQuality = PROOF\_QUALITY; //NEW
      lstrcpy(lf.lfFaceName, "Times New Roman");  //"Courier");
      VERIFY(font.CreateFontIndirect(&lf));
      
      dc->SetMapMode (MM\_ISOTROPIC) ;
      dc->SetWindowExt ( 1000, 1000) ;
      dc->SetViewportExt (cxPage / 2, -cyPage / 2) ;
      dc->SetViewportOrg (cxPage / 2,  cyPage / 2) ;
      dc->SetTextAlign(TA\_BASELINE | TA\_CENTER);
      dc->SetBkMode(OPAQUE);
      dc->SetMapMode(MM\_TEXT);
      dc->PatBlt(0, 0, sizePrn.cx, sizePrn.cy, WHITENESS);
      dc->LPtoDP(&sizePrn);
      dc->SelectObject(&font) ;
      
       CSize extentChar = dc ->GetTextExtent("M",1);
       int nCharHeight  = extentChar.cy+4;
       int nCharWidth	  = extentChar.cx+10;     
      

      // Begin printing the doc
      BeginWaitCursor();

      CString printDate = GetMyCurDateTime();
      
      DOCINFO docinfo;
      memset(&docinfo, 0, sizeof(docinfo));
      docinfo.cbSize = sizeof(docinfo);
      docinfo.lpszDocName = \_T("Calif Lottery Winnings");
      docinfo.fwType = 0;
      
      
      rc = dc->StartDocA(&docinfo);
      if (rc < 0)
      {
      	sprintf(temp, "Unable to Begin printing - Error\[%d\]", rc);
      	MessageBox(temp, NULL, MB\_OK);
      	dc->ReleaseAttribDC();
      	dc->ReleaseOutputDC();
      	dc->DeleteTempMap();
      	EndWaitCursor();
      	DeleteDC(pd.hDC);
      	if(pd.hDevMode != NULL)
      		GlobalFree(pd.hDevMode);
      	if(pd.hDevNames != NULL)
      		GlobalFree(pd.hDevNames);
      	dc = 0;
      	return;
      }
      szTitle=CString("California Lottery System Printout     ") + printDate;
      //Print a Page Header
      dc -> StartPage();
      dc -> SetTextAlign(TA\_LEFT | TA\_TOP);
      dc -> TextOut(0, 0, szTitle, szTitle.GetLength() );
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      When things get too complicate (re: printing), I create "forms" / pages / windows that match the required output; then "capture" the visual and print that in one go (as an "image" or whatever). Total WYSIWYG. Users can even "update" the "report" (if you let them).

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      I 1 Reply Last reply
      0
      • L Lost User

        When things get too complicate (re: printing), I create "forms" / pages / windows that match the required output; then "capture" the visual and print that in one go (as an "image" or whatever). Total WYSIWYG. Users can even "update" the "report" (if you let them).

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        I Offline
        I Offline
        inlandchris1
        wrote on last edited by
        #3

        That is a good idea, will look into it.

        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