方法一:字串超长时不会换行
CString strText=m_txt+"\n"; int iPos = strText.Find(‘\n‘); int iLen=strlen(strText); int iAbsPos =0; CString str; while(iPos > -1){ str = strText.Mid(0,iPos+1); nPosY=3*m_cyPrinter*(12+j); j=j+1; pDC->TextOut(nPosX,nPosY,str); } strText = strText.Mid(iPos + 1); iPos = strText.Find(‘\n‘); } 方法二:最有效的
int nn=m_test.GetLineCount();
int itPos; // int j=0; for (int i=0;i<nn;i++) { nPosY=m_cyPrinter*(12+i); itPos = m_test.LineLength(i); m_test.GetLine(i,str.GetBuffer(itPos)); str.ReleaseBuffer(); pDC->TextOut(nPosX,nPosY,str); } 方法三:可以得到的矩形区域
FORMATRANGE fr;
// Get the page width and height from the printer.
long lPageWidth =pDC->GetDeviceCaps(PHYSICALWIDTH);// ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH), 1440, pDC->GetDeviceCaps(LOGPIXELSX)); long lPageHeight =pDC->GetDeviceCaps(PHYSICALHEIGHT); //::MulDiv(pDC->GetDeviceCaps(PHYSICALHEIGHT), 1440, pDC->GetDeviceCaps(LOGPIXELSY)); CRect rcPage(nPosX ,nPosY,lPageWidth,lPageHeight);//lPageWidth, lPageHeight); pDC->SetMapMode(MM_ANISOTROPIC); // 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_test.FormatRange(&fr, TRUE); m_test.DisplayBand(&rcPage); |
|
来自: haixinhope > 《vc》