Click here to Skip to main content
11,481,838 members (65,388 online)

C / C++ / MFC

 
QuestionMultiMon/Multi-VideoCards/Multi-Displays With Multiple DirectDraw FullScreen Exclusive Applications. Pin
bowen198127-Sep-12 6:30
memberbowen198127-Sep-12 6:30 
AnswerRe: MultiMon/Multi-VideoCards/Multi-Displays With Multiple DirectDraw FullScreen Exclusive Applications. Pin
ihoecken28-Sep-12 3:00
memberihoecken28-Sep-12 3:00 
QuestionHighlighting Control based on Selection Pin
Don Guy27-Sep-12 4:52
memberDon Guy27-Sep-12 4:52 
AnswerRe: Highlighting Control based on Selection Pin
Jochen Arndt27-Sep-12 6:04
memberJochen Arndt27-Sep-12 6:04 
AnswerRe: Highlighting Control based on Selection Pin
Marius Bancila1-Oct-12 23:12
memberMarius Bancila1-Oct-12 23:12 
Questionhow to use the outside class Pin
yu-jian27-Sep-12 4:18
groupyu-jian27-Sep-12 4:18 
AnswerRe: how to use the outside class Pin
DavidCrow27-Sep-12 4:27
memberDavidCrow27-Sep-12 4:27 
QuestionPrinting with CRichEditCtrl control Pin
sdancer7527-Sep-12 0:05
membersdancer7527-Sep-12 0:05 
Hi,

I am trying to print the content of the CRichEditCtrl. The problem is that when I want to use pagination (with A4 pages), the printed text (which is just 4 sample line with 40 chars at most) at the code
lTextPrinted =FormatRange(&fr,TRUE);
is always lesser than the actual text pointed by the lTextLength variable making the loop run for ever. What is the problem with the following code ?




 
	CPrintDialog printDialog(false);
	
	
	if (bShowPrintDialog)
	{
		int r = printDialog.DoModal();
		if (r == IDCANCEL)
			return; // User pressed cancel, don't print.
	}
	else
	{
		printDialog.GetDefaults();
	}
 
	HDC hPrinterDC = printDialog.GetPrinterDC();
	
	CDC pMyPrinterDC; 
	pMyPrinterDC.Attach(hPrinterDC);
 

 

 
	// This code basically taken from MS KB article Q129860 
	
	FORMATRANGE fr;
	  int	  nHorizRes = GetDeviceCaps(hPrinterDC, HORZRES);
	  int	  nVertRes = GetDeviceCaps(hPrinterDC, VERTRES);
      int     nLogPixelsX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
	  int     nLogPixelsY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
	  LONG	  lTextLength;   // Length of document.
	  LONG	  lTextPrinted;  // Amount of document printed.

	 // Ensure the printer DC is in MM_TEXT mode.
	  SetMapMode ( hPrinterDC, MM_TEXT );
 
	 // Rendering to the same DC we are measuring.
	  //ZeroMemory(&fr, sizeof(fr));
	  fr.hdc = pMyPrinterDC.m_hDC;
	  fr.hdcTarget = pMyPrinterDC.m_hDC;
 
	  // Get the page width and height from the printer.
	  long lPageWidth =  ::MulDiv(pMyPrinterDC.GetDeviceCaps(PHYSICALWIDTH), 1440, pMyPrinterDC.GetDeviceCaps(LOGPIXELSX));
	  long lPageHeight = ::MulDiv(pMyPrinterDC.GetDeviceCaps(PHYSICALHEIGHT), 1440, pMyPrinterDC.GetDeviceCaps(LOGPIXELSY));
	  CRect rcPage(0, 0, lPageWidth, lPageHeight);
 
	  SetTargetDevice(hPrinterDC,lPageWidth);
 
	  fr.rc = rcPage;
	  fr.rcPage = rcPage;
 

	 // Default the range of text to print as the entire document.
	  fr.chrg.cpMin = 0;
	  fr.chrg.cpMax = -1;
      this->FormatRange(&fr,TRUE);      
 
	 // Set up the print job (standard printing stuff here).
	  DOCINFO di;
	  ZeroMemory(&di, sizeof(di));
	  di.cbSize = sizeof(DOCINFO);
 
	  di.lpszDocName = "GnosisExplorerNotes";
 
	  // Do not print to file.
	  di.lpszOutput = NULL;
	     
	// Update the display with the new formatting.
	  RECT rcClient;
      GetClientRect(&rcClient);
      DisplayBand(&rcClient); 
 
	 // Start the document.
	  StartDoc(hPrinterDC, &di);
 
	 // Find out real size of document in characters.
	 lTextLength = GetTextLength();//SendMessage ( /*hRTFWnd,*/ WM_GETTEXTLENGTH, 0, 0 );
	 //lTextLength = ::SendMessage (this->m_hWnd, WM_GETTEXTLENGTH, 0, 0); 

	 do {
	     // Start the page.
	     StartPage(hPrinterDC);
 
	    // Print as much text as can fit on a page. The return value is
	     // the index of the first character on the next page. Using TRUE
	     // for the wParam parameter causes the text to be printed.

		//lTextPrinted = ::SendMessage (this->m_hWnd, EM_FORMATRANGE, FALSE, (LPARAM)&fr); 	    
		lTextPrinted =FormatRange(&fr,TRUE);
		
		DisplayBand(&fr.rc );
	    
	    // Print last page.
	    EndPage(hPrinterDC);
 
	    // If there is more text to print, adjust the range of characters
	     // to start printing at the first character of the next page.
		if (lTextPrinted < lTextLength)	{
			fr.chrg.cpMin = lTextPrinted;
			fr.chrg.cpMax = -1;
		}
 
	  } while (lTextPrinted < lTextLength);
 
	 // Tell the control to release cached information.
	  FormatRange(NULL,false);
	 //SendMessage( EM_FORMATRANGE, 0, (LPARAM)NULL);

	 EndDoc (hPrinterDC);
 
	  ///////
	  
	DeleteDC(hPrinterDC);
	pMyPrinterDC.DeleteDC();
 
sdancer75

AnswerRe: Printing with CRichEditCtrl control [modified] Pin
sdancer755-Oct-12 4:55
membersdancer755-Oct-12 4:55 
GeneralRe: Printing with CRichEditCtrl control Pin
Andrew Cherednik7-Oct-12 19:44
memberAndrew Cherednik7-Oct-12 19:44 
GeneralRe: Printing with CRichEditCtrl control Pin
sdancer757-Oct-12 21:21
membersdancer757-Oct-12 21:21 
QuestionQuality based Video encoding in H.264 Codec Pin
Ajesh Kumar.T.T26-Sep-12 22:01
memberAjesh Kumar.T.T26-Sep-12 22:01 
QuestionHow to Convert palette buffer to RGB buffer Pin
Ajesh Kumar.T.T26-Sep-12 22:00
memberAjesh Kumar.T.T26-Sep-12 22:00 
AnswerRe: How to Convert palette buffer to RGB buffer Pin
CPallini26-Sep-12 23:09
mvpCPallini26-Sep-12 23:09 
QuestionDialogBox 64bit ? Pin
Smart Arab26-Sep-12 1:07
memberSmart Arab26-Sep-12 1:07 
AnswerRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 3:42
mvpRichard MacCutchan26-Sep-12 3:42 
QuestionRe: DialogBox 64bit ? Pin
CPallini26-Sep-12 4:40
mvpCPallini26-Sep-12 4:40 
AnswerRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 6:01
memberSmart Arab26-Sep-12 6:01 
GeneralRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 6:12
mvpRichard MacCutchan26-Sep-12 6:12 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 6:54
memberSmart Arab26-Sep-12 6:54 
GeneralRe: DialogBox 64bit ? Pin
Jochen Arndt26-Sep-12 7:10
memberJochen Arndt26-Sep-12 7:10 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 23:45
memberSmart Arab26-Sep-12 23:45 
GeneralRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 7:29
mvpRichard MacCutchan26-Sep-12 7:29 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 23:42
memberSmart Arab26-Sep-12 23:42 
GeneralRe: DialogBox 64bit ? Pin
CPallini26-Sep-12 12:47
mvpCPallini26-Sep-12 12:47 

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

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


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 24 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid