Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Print CRichEditCtrl from CView

Print CRichEditCtrl from CView

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Pokluda
    wrote on last edited by
    #1

    I have this problem. I have CView derived class. In the OnCreate function I create a CRichEditCtrl like this: AfxInitRichEdit(); m_richEdit.Create(ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, rect, this, 1); where m_richEdit is a CRichEditCtrl variable defined in the header file of my CView class. In OnSize I set the appropriate size of the control. Now I have this problem. What do I have to do to print the contents of the m_richEdit and to see the contents of this in Print Preview. I have tried many thinks, but I failed. Thank you very much. David Pokluda pokluda@mujweb.cz

    J 1 Reply Last reply
    0
    • D David Pokluda

      I have this problem. I have CView derived class. In the OnCreate function I create a CRichEditCtrl like this: AfxInitRichEdit(); m_richEdit.Create(ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, rect, this, 1); where m_richEdit is a CRichEditCtrl variable defined in the header file of my CView class. In OnSize I set the appropriate size of the control. Now I have this problem. What do I have to do to print the contents of the m_richEdit and to see the contents of this in Print Preview. I have tried many thinks, but I failed. Thank you very much. David Pokluda pokluda@mujweb.cz

      J Offline
      J Offline
      jschacker
      wrote on last edited by
      #2

      I have done this with a CView derived child (CScrollView) but not with a CWnd derived child. With the CView child the code looked like this: void CViewClass::OnPrint(CDC* pDC, CPrintInfo* pInfo) { //Resize the child if needed. m_child.MoveWindow(&m_rectChild, TRUE); //Print the child. m_child.OnPrint(pDC, pInfo); //Call the base class. CView::OnPrint(pDC, pInfo); } Now the CWnd child does not have the OnPrint(...) method. But you may be able to use the CWnd::Print(CDC* pDC, DWORD dwFlags) method instead. Please let me know if it works... Jonathan Craig

      J 1 Reply Last reply
      0
      • J jschacker

        I have done this with a CView derived child (CScrollView) but not with a CWnd derived child. With the CView child the code looked like this: void CViewClass::OnPrint(CDC* pDC, CPrintInfo* pInfo) { //Resize the child if needed. m_child.MoveWindow(&m_rectChild, TRUE); //Print the child. m_child.OnPrint(pDC, pInfo); //Call the base class. CView::OnPrint(pDC, pInfo); } Now the CWnd child does not have the OnPrint(...) method. But you may be able to use the CWnd::Print(CDC* pDC, DWORD dwFlags) method instead. Please let me know if it works... Jonathan Craig

        J Offline
        J Offline
        jschacker
        wrote on last edited by
        #3

        The CWnd::Print(…) method will not work. But the CRichEditCtrl knows how to render itself to a device context. The code below will work. I didn’t have a chance to figure out the formatting. You need to look up the FORMATRANGE structure in the MSDN. The code below was cut and pasted for the MSDN article CRichEditCtrl::FormatRange. Also look at the MSDN article Printing in Rich Edit Controls. If you don’t have MSDN you can search Microsoft’s web site. void CPrintChildWindowView::OnPrint(CDC* pDC, CPrintInfo* pInfo) { FORMATRANGE fr; long lPageWidth = ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH), 1440, pDC->GetDeviceCaps(LOGPIXELSX)); long lPageHeight = ::MulDiv(pDC->GetDeviceCaps(PHYSICALHEIGHT), 1440, pDC->GetDeviceCaps(LOGPIXELSY)); CRect rcPage(0, 0, lPageWidth, lPageHeight); // Format the text and render it to the printer. fr.hdc = pDC->m_hDC; fr.hdcTarget = pDC->m_hDC; fr.rc = rcPage; fr.rcPage = rcPage; fr.chrg.cpMin = 0; fr.chrg.cpMax = -1; m_pREC->FormatRange(&fr, TRUE); // Update the display with the new formatting. RECT rcClient; m_pREC->GetClientRect(&rcClient); m_pREC->DisplayBand(&rcClient); CView::OnPrint(pDC, pInfo); } Good Luck, Jonathan Craig

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups