Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir
as am very new to the MFC just started working.
i am facing difficulties to scroll the window which has fixed text. i am not able to scroll the text both way horizontal and vertical please any one help me with example or code.





thanking you
sarfaraz
Posted

You need to use the CScrollView[^] class; try a Google search for examples.
 
Share this answer
 
If you used the CScrollView for the application then just
call following method
void CScrollBarDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int CurPos = m_ScrollBar.GetScrollPos();
	// Determine the new position of scroll box.
	switch (nSBCode)
	{
	case SB_LEFT:      // Scroll to far left.
		CurPos = 0;
		break;
	case SB_RIGHT:      // Scroll to far right.
		CurPos = 122;
		break;
	case SB_ENDSCROLL:   // End scroll.
		break;
	case SB_LINELEFT:      // Scroll left.
		if (CurPos > 0)
			CurPos--;
		break;
	case SB_LINERIGHT:   // Scroll right.
		if (CurPos < 122)
			CurPos++;
		break;
	case SB_PAGELEFT:    // Scroll one page left.
		{
			// Get the page size. 
			SCROLLINFO   info;
			m_ScrollBar.GetScrollInfo(&info, SIF_ALL);
   
			if (CurPos > 0)
				CurPos = max(0, CurPos - (int) info.nPage);
		}
		break;
	case SB_PAGERIGHT:      // Scroll one page right
		{
			// Get the page size. 
			SCROLLINFO   info;
			m_ScrollBar.GetScrollInfo(&info, SIF_ALL);
			if (CurPos < 122)
				CurPos = min(122, CurPos + (int) info.nPage);
		}
		break;
	case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
		CurPos = nPos;      // of the scroll box at the end of the drag operation.
		break;
	case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
		CurPos = nPos;     // position that the scroll box has been dragged to.
		break;
	}
	// Set the new position of the thumb (scroll box).
	m_ScrollBar.SetScrollPos(CurPos);
	
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}




///////bit you use CEditCntrl then Define the object of scrollview like CSrollbar and add following code in OnDraw() method

m_ScrollBar.SetScrollRange(0, 122);
 
Share this answer
 
v2
Comments
JF2015 22-Feb-11 0:33am    
Added code formatting.
sarfaraznawaz 22-Feb-11 0:44am    
thanks ......
[no name] 22-Feb-11 0:59am    
its ok
same goes for VSCrollview

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