Click here to Skip to main content
15,889,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMultiMon/Multi-VideoCards/Multi-Displays With Multiple DirectDraw FullScreen Exclusive Applications. Pin
bowen198127-Sep-12 5:30
bowen198127-Sep-12 5:30 
AnswerRe: MultiMon/Multi-VideoCards/Multi-Displays With Multiple DirectDraw FullScreen Exclusive Applications. Pin
Ingo28-Sep-12 2:00
Ingo28-Sep-12 2:00 
QuestionHighlighting Control based on Selection Pin
Don Guy27-Sep-12 3:52
Don Guy27-Sep-12 3:52 
AnswerRe: Highlighting Control based on Selection Pin
Jochen Arndt27-Sep-12 5:04
professionalJochen Arndt27-Sep-12 5:04 
AnswerRe: Highlighting Control based on Selection Pin
Marius Bancila1-Oct-12 22:12
professionalMarius Bancila1-Oct-12 22:12 
Questionhow to use the outside class Pin
yu-jian27-Sep-12 3:18
yu-jian27-Sep-12 3:18 
AnswerRe: how to use the outside class Pin
David Crow27-Sep-12 3:27
David Crow27-Sep-12 3:27 
QuestionPrinting with CRichEditCtrl control Pin
sdancer7526-Sep-12 23:05
sdancer7526-Sep-12 23: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
C++
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 ?




C++
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 Pin
sdancer755-Oct-12 3:55
sdancer755-Oct-12 3:55 
GeneralRe: Printing with CRichEditCtrl control Pin
chaau7-Oct-12 18:44
chaau7-Oct-12 18:44 
GeneralRe: Printing with CRichEditCtrl control Pin
sdancer757-Oct-12 20:21
sdancer757-Oct-12 20:21 
QuestionQuality based Video encoding in H.264 Codec Pin
Ajesh Kumar.T.T26-Sep-12 21:01
Ajesh Kumar.T.T26-Sep-12 21:01 
QuestionHow to Convert palette buffer to RGB buffer Pin
Ajesh Kumar.T.T26-Sep-12 21:00
Ajesh Kumar.T.T26-Sep-12 21:00 
AnswerRe: How to Convert palette buffer to RGB buffer Pin
CPallini26-Sep-12 22:09
mveCPallini26-Sep-12 22:09 
QuestionDialogBox 64bit ? Pin
Smart Arab26-Sep-12 0:07
Smart Arab26-Sep-12 0:07 
AnswerRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 2:42
mveRichard MacCutchan26-Sep-12 2:42 
QuestionRe: DialogBox 64bit ? Pin
CPallini26-Sep-12 3:40
mveCPallini26-Sep-12 3:40 
AnswerRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 5:01
Smart Arab26-Sep-12 5:01 
GeneralRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 5:12
mveRichard MacCutchan26-Sep-12 5:12 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 5:54
Smart Arab26-Sep-12 5:54 
GeneralRe: DialogBox 64bit ? Pin
Jochen Arndt26-Sep-12 6:10
professionalJochen Arndt26-Sep-12 6:10 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 22:45
Smart Arab26-Sep-12 22:45 
GeneralRe: DialogBox 64bit ? Pin
Richard MacCutchan26-Sep-12 6:29
mveRichard MacCutchan26-Sep-12 6:29 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 22:42
Smart Arab26-Sep-12 22:42 
GeneralRe: DialogBox 64bit ? Pin
CPallini26-Sep-12 11:47
mveCPallini26-Sep-12 11:47 

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.