[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

GetScrollPosition...how do you interpret the point?

Posted on 2004-08-23
6
Medium Priority
?
236 Views
Last Modified: 2013-12-03
Hi.  I am trying to do something very simple.  I have a CScrollView, and I've made my document size 500x500.  When I scroll the view vertically and then click in it, I write to the view at two different points -- one where I clicked and one at the y-coordinate of the scrollPosition  Here is the code:

void CMyScrollView::OnLButtonDown(UINT nFlags, CPoint point)
{
  CPoint scrollPos = GetScrollPosition();      
  CDC *pDC = GetDC();
  pDC->TextOut(0, point.y, "point");
  pDC->TextOut(0, scrollPos.y, "scrPos");
}

The problem is that when I write to scrollPos.y, it consistently writes at a point below the top of the thumb in the scroll bar.  What does scrollPos.y really represent?   Is it the top of the thumb, bottom of the thumb, middle of the thumb, etc...?  Do I need to do some more math on the scroll position or is the scroll position some other point on the scroll bar?  Thanks.

0
Comment
Question by:mromeo
[X]
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
  • 3
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11875245
scrollPos.y reflect the position of the top visible portion of the document (not of the thumb), expressed in logical units. If you want the coordinate expressed in device units, then use GetDeviceScrollPosition().

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 11877991
Get the whole size of the document in pixels (visible plus invisible parts) and divide it to the scroll range. The number you get is scroll unit in pixels. When user clicks scrollbar arrow, document is scrolled to one unit. Scroll position is number of such units from the beginning of the document.
0
 

Author Comment

by:mromeo
ID: 11880963
So, jaime, are you saying that the scroll position.y represnets the top portion of the document that you cannot see and that it does NOT include the position that the thumb is scrolled to?  To me, this means that if a user clicks in the view, the "real" point that was clicked is point + scroll position.  Does this sound correct?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11881336
0
 

Author Comment

by:mromeo
ID: 11881609
I think we're trying to say the same thing in two different ways.  What I was trying to say was that the scroll position is positioned at the point where visible and invisible parts of the window meet.  For example:

  ------------------------------------
  |                                          |
  |                                          |
  |                                          |
  ------------------------------------   <--  scroll pos = 60 (there are 60 pixels above line)
  |                                          |  
  |       . <-- pt = 25                 |
  |                                          |
  |                                          |
   ------------------------------------

If there are 60 pixels above the line and 80 below, then to get the "real" position of the point, you need to add 60 + 25.  

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 total points
ID: 11882116
Sorry, a little bussy.

About your question: YES. Just do this:

void CMyScrollView::OnLButtonDown(UINT nFlags, CPoint point)
{
  CPoint scrollPos = GetScrollPosition();
  pos += point;

   // continue working with pos
}

Also, it is recommendable to use   SetScrollSizes(MM_TEXT, CSize(width,height)); with the MM_TEXT attribute to avoid to deal with scaling issues: 1 logical unit = 1 pixel in this case.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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 article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 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