CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Location
    Jodhpur -> Rajasthan -> INDIA
    Posts
    453

    Multiline text on View

    Hello

    MFC+SDI application

    I want to put multiline text on the view.
    User enters text into edit box and then clicks insert comments button.
    Comments has to be printed over the defaults Comments place.
    If text is more than that fits to a A-4 page setup then it has to be wrapped and to be in multiline

    How to do this?
    Leave Your Mark Wherever You Go
    http://www.danasoft.com/sig/d0153030Sig.jpg

  2. #2
    Join Date
    May 2003
    Location
    Jodhpur -> Rajasthan -> INDIA
    Posts
    453
    I am using CDC's function DrawText with format set as DT_TOP|DT_LEFT
    Leave Your Mark Wherever You Go
    http://www.danasoft.com/sig/d0153030Sig.jpg

  3. #3
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    Use a scrolling view, not a CView

    //Set up your page, scroll sizes in OnInitialUpdate


    Code:
    void CScrollTextView::OnInitialUpdate()
    {
    	CScrollView::OnInitialUpdate();
    
    	CDC* pDC = GetDC();
    	ASSERT_VALID(pDC);
    	CRect rcPrint;
                    //getMargins() is inline - returns 50, 50, 50, 50 Rect
                    //  1/2" margins
    	ASSERT(getPrintRect(pDC, rcPrint, getMargins()));
    	ReleaseDC(pDC);
    	//Total print area
    	CSize sizeTotal(rcPrint.Width(), rcPrint.Height());		
    	//A scrolling page will be 1/2 the total print area
    	CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
    	//A line scroll will be 25th of the total print area
    	CSize sizeLine(sizeTotal.cx / 25, sizeTotal.cy / 25);
    	SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
    }
    Helper fxn - if you are using A4 paper change the paper size in this fxn
    Code:
    BOOL CScrollTextView::getPrintRect(CDC* pDC, CRect & rcPrint, 
    				const CRect & rcLoEnglishMargins)
    {
    	ASSERT_VALID(pDC);
    	//Logical inches
    	int logX = pDC->GetDeviceCaps(LOGPIXELSX);
    	int logY = pDC->GetDeviceCaps(LOGPIXELSY);
    	//8.5 X 11 paper
    	CRect rcPage(0, 0, MulDiv(logX, 17, 2), logY * 11);
    	//Printable portion of page
    	rcPrint.left = rcPage.left + MulDiv(rcLoEnglishMargins.left, logX, 100);
    	rcPrint.top = rcPage.top + MulDiv(rcLoEnglishMargins.top, logY, 100);
    	rcPrint.right = rcPage.right - MulDiv(rcLoEnglishMargins.right, logX, 100);
    	rcPrint.bottom = rcPage.bottom - MulDiv(rcLoEnglishMargins.bottom, logY, 100);
    	if (pDC->IsPrinting())
    	{
    		//Adjust for physical offset of printer.  Usually this shifts
    		//toward left and top.  Calling fxn doesn't need to adjust
    		//viewport origin
    		int xOffset = pDC->GetDeviceCaps(PHYSICALOFFSETX);
    		int yOffset = pDC->GetDeviceCaps(PHYSICALOFFSETY);
    		rcPrint.OffsetRect(-xOffset, -yOffset);
    	}
    	else
    		//WYSIWYG but without the margins
    		rcPrint.OffsetRect(-rcPrint.left, -rcPrint.top);
    	return TRUE;
    }
    //An example OnDraw()
    Code:
    void CScrollTextView::OnDraw(CDC* pDC)
    {
    	CRect rcPrint;
    	// 1/2" margins
    	ASSERT(getPrintRect(pDC, rcPrint, getMargins()));
    	CFont font;
    	font.CreatePointFont(120, _T("Times New Roman"), pDC);
    	CFont* pOldFont = pDC->SelectObject(&font);
    	CString strText = _T("Now is the time for all good men to come to the"
    		" aid of their country.  This is the mantra used in beginning typing"
    		" class to train the brain to distinguish right from left and "
    		" develop speed with accuracy.");
    	pDC->DrawText(strText, &rcPrint, DT_WORDBREAK);
    	pDC->SelectObject(pOldFont);
    	font.DeleteObject();	
    }
    Hope this helps.
    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured