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

C / C++ / MFC

 
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 
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 
Here is the code that prints very well:

C++
// this code is taken from Vadim Z.'s article RTF based Tooltips
// www.codeguru.com
//----------------------------------------------------------------------------
// Function CMyRichEditCtrl::Print
// @func    print the rich edit control content
// @parm    bool  | bShowPrintDialog | show the dialog box CPrintDialog
//----------------------------------------------------------------------------
// @todo 
//----------------------------------------------------------------------------
void CSpscRichEditCtrl::Print(bool bShowPrintDialog, CWnd* pParent /*=NULL*/)
{
  CPrintDialog printDialog(false, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
      | PD_HIDEPRINTTOFILE | PD_NOSELECTION, pParent);

  if (bShowPrintDialog)
  {
    int r = printDialog.DoModal();
    if (r == IDCANCEL)
      return; // User pressed cancel, don't print.
  }
  else
  {
    printDialog.GetDefaults();
  }

  HDC hPrinterDC = printDialog.GetPrinterDC();

  // 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 );

  // Tell the control to release cached information.
  FormatRange(NULL,false);      

  // Rendering to the same DC we are measuring.
  ZeroMemory(&fr, sizeof(fr));
  fr.hdc = fr.hdcTarget = hPrinterDC;

  // Set up the page.
  fr.rcPage.left     = fr.rcPage.top = 0;
  fr.rcPage.right    = (nHorizRes/nLogPixelsX) * 1440;
  fr.rcPage.bottom   = (nVertRes/nLogPixelsY) * 1440;

  // Set up 0" margins all around.
  fr.rc.left   = fr.rcPage.left ;//+ 1440;  // 1440 TWIPS = 1 inch.
  fr.rc.top    = fr.rcPage.top ;//+ 1440;
  fr.rc.right  = fr.rcPage.right ;//- 1440;
  fr.rc.bottom = fr.rcPage.bottom ;//- 1440;

  // Default the range of text to print as the entire document.
  fr.chrg.cpMin = 0;
  fr.chrg.cpMax = -1;
  // Set up the print job (standard printing stuff here).
  DOCINFO di;
  ZeroMemory(&di, sizeof(di));
  di.cbSize = sizeof(DOCINFO);

  di.lpszDocName = _T("eClinic Pharmacy SMS Authorisation Form");

  // Do not print to file.
  di.lpszOutput = NULL;


  // Start the document.
  StartDoc(hPrinterDC, &di);

  // Find out real size of document in characters.
  //lTextLength = GetTextLength();
  lTextLength = GetTextLengthEx(GTL_PRECISE | GTL_NUMCHARS);

  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 =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);


  EndDoc (hPrinterDC);

  ///////

  DeleteDC(hPrinterDC);

}

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 
GeneralRe: DialogBox 64bit ? Pin
Smart Arab26-Sep-12 22:39
Smart Arab26-Sep-12 22:39 
GeneralRe: DialogBox 64bit ? Pin
CPallini26-Sep-12 22:45
mveCPallini26-Sep-12 22:45 

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.