Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Scrolling causing problem

i am working in doc/view architecture and myview class is derived fron cscrollview.on my view i am getting the text written on it using textout.now the probelmis this that when i scroll the view the text get deleted and do not repaint.i want that scroll bar work in the normal way i.e. do no clear the view but it is not can u help me.
1 Solution
You constantly need to redraw client area even when the window has been scrolled .
In the OnDraw() method call TextOut method for example.
But you can limit the amount of displayed text by getting the scroll position with CScrollView::GetScrollPosition() for example
Please show your OnDraw function and setting scroll size (I guess you do this in OnUpdate).
I hate to attempt to answer something that someone has mostly answered, however, there are a couple of things that can be added, so I will add them.

First, when using CScrollView, you must be aware of the limitation of its scroll range.  When I've used it, the ration was set such that each number in the scroll bar's range mapped to exactly one virtual pixel.  Obviously CScrollView is supposed to give the programmer the feeling they are working with one huge display.  However, one gotcha is the limit of the scroll view is somewhere around 32,000.  Given a small font height such as 10 pixels high, you can only have about 3,2000 rows in a CScrollView.  Depending upon your font size, that may get bigger or smaller.  The same can be said about the horizontal scrolling, only the width of most fonts is less than the height, so you might get about 4,000 columns.  This is a real problem which caused me to write my own scroll view class.  My class is smart enough to calculate some form of ratio such that I can simulate displays well beyond 32,000 pixels high.  However if you don't ever intend to put much data in the scroll view and your font height is small, don't worry about it.

Second, when drawing to the screen, understand there will be clipping occuring in the background.  That is, if you draw at Y = 0, you are drawing at the top of the page.  If the scroll bar is beyond the top of the page, CScrollView simply clips what you are drawing.  Therefore, you should use your X and Y value of the scroll bar for where you are drawing.  This bit me.

Also, if you are displaying text, you may need to adjust the origin so your scrolling looks nice and smooth.  Example, If you have a font that is 10 pixels heigh and 8 pixels wide, and the user scrolls the horizontal scroll bar by 2, you may want to show the rightmost 6 pixels of your first column of text.

If you have any other questions, please ask.

Good Luck,

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now