Scrolling causing problem

Posted on 2003-03-27
Medium Priority
Last Modified: 2013-11-20
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.
Question by:Zulqernain
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8217564
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
LVL 48

Expert Comment

ID: 8217566
Please show your OnDraw function and setting scroll size (I guess you do this in OnUpdate).

Accepted Solution

Catalepsy earned 750 total points
ID: 8218584
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question