Thread: Printing using DrawText() or TextOut()

  1. #1
    Registered User
    Join Date
    May 2004

    Printing using DrawText() or TextOut()


    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.

    void CDEPDlg::OnPrintEditControl() {
    	//// Create a printer DC    
    	CPrintDialog dlg(FALSE);     
    	CDC dc; 
        #if 0 //Show print dialog.    
    	if (dlg.DoModal() == IDCANCEL)        
        #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.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;   
    	dc.DrawText(sText, printArea, DT_NOPREFIX | DT_WORDBREAK); 
    	//End printing    
    Thanks for the help

  2. #2
    Join Date
    Jan 2002
    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, 01:13 AM
  2. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02: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