Printing using DrawText() or TextOut()

This is a discussion on Printing using DrawText() or TextOut() within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I am printing information from combo boxes and edit boxes out on paper, and at the moment I am ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    3

    Printing using DrawText() or TextOut()

    Hey,

    I am printing information from combo boxes and edit boxes out on paper, and at the moment I am using DrawText(). But I don't know how to get it to draw it in a different place. I looked at TextOut() and it had int x and int y, so like coordinates. Would that be better for waht I am doing or does someone know how to move the draw text around?

    Here is my code so you can see how it is being done.

    Code:
    void CDEPDlg::OnPrintEditControl() {
    	//// Create a printer DC    
    	CPrintDialog dlg(FALSE);     
    	CDC dc; 
    
        #if 0 //Show print dialog.    
    	if (dlg.DoModal() == IDCANCEL)        
    		return;    
    	dc.Attach(dlg.GetPrinterDC());
        #else //Don't show print dialog.   
    	PRINTDLG prtDlg;    
    	AfxGetApp()->GetPrinterDeviceDefaults(&prtDlg); //Should check for error.   
    	dlg.m_pd.hDevMode = prtDlg.hDevMode;   
    	dlg.m_pd.hDevNames = prtDlg.hDevNames;    
    	dc.Attach(dlg.CreatePrinterDC());
    	#endif    
    	dc.m_bPrinting = TRUE; 
    	//// Now use the DC.    
    	//Get the page size.    
    	CRect printArea;    
    	printArea.SetRect(0, 0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));     
    	//Start printing.    
    	DOCINFO docinfo;    
    	memset(&docinfo, 0, sizeof(docinfo));    
    	docinfo.cbSize = sizeof(docinfo);    
    	docinfo.lpszDocName = _T("Edit Control Print");     
    	dc.StartDoc(&docinfo); //Should check for error.    
    	dc.StartPage();        //Should check for error.         
    	//Draw the edit control contents.    
    	CString sText;   
    	m_type1.GetWindowText(sText);    
    	dc.DrawText(sText, printArea, DT_NOPREFIX | DT_WORDBREAK); 
    	//End printing    
    	dc.EndPage();    
    	dc.EndDoc();
    
    }
    Thanks for the help

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Code:
    printArea.SetRect(0, 0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
    Change the values there to modify the CDC::DrawText rectangle (or 'print area' as you have it). dc.GetDeviceCaps(HORZRES) and dc.GetDeviceCaps(VERTRES) are the maximum width and height respectively, the first two parameters, which you have currently set to zero, are left and top ( or 'x' and 'y', like TextOut).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 02:13 AM
  2. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 03:20 AM
  3. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM
  5. DrawText() and TextOut() newbie question
    By Cardassian in forum Windows Programming
    Replies: 3
    Last Post: 02-23-2003, 10:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21