Print CRichEditCtrl from CView
-
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
-
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
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
-
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
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