Click here to Skip to main content
15,891,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have place a rich edit control in a class derived from cview.. I want to print the contents of the contrl.Please help me in doing the same.....
Posted
Comments
Sandeep Mewara 25-Jul-12 13:42pm    
I want to print the contents of the contrl
So, did you try to do it? Where are you stuck?

1 solution

The rich edit control do the printing if you ask it in the OnPrint method:

C++
void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDC);

	FORMATRANGE fr;
	CRect rect;
	
	// offset by printing offset
	pDC->SetViewportOrg(-pDC->GetDeviceCaps(PHYSICALOFFSETX),
		-pDC->GetDeviceCaps(PHYSICALOFFSETY));
	
	// adjust DC because richedit doesn't do things like MFC
	if (::GetDeviceCaps(pDC->m_hDC, TECHNOLOGY) != DT_METAFILE && pDC->m_hAttribDC != NULL)
	{
		::ScaleWindowExtEx(pDC->m_hDC,
			::GetDeviceCaps(pDC->m_hDC, LOGPIXELSX),
			::GetDeviceCaps(pDC->m_hAttribDC, LOGPIXELSX),
			::GetDeviceCaps(pDC->m_hDC, LOGPIXELSY),
			::GetDeviceCaps(pDC->m_hAttribDC, LOGPIXELSY),
			NULL);
	}
	// Set range for rendering
	fr.hdcTarget = pDC->m_hAttribDC;
	fr.hdc = pDC->m_hDC;
	fr.rcPage = GetPageRect();
	fr.rc = GetPrintRect();
	fr.chrg.cpMin = 0;
	fr.chrg.cpMax = fr.chrg.cpMin + GetWindowTextLength();
	GetRichEditCtrl().FormatRange(&fr, TRUE);
}



That's only the print method. You should to do some settings in the OnBeginPrinting & OnEndOPrinting if you need change settings before print or clean up after that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900