tags:

views:

351

answers:

4

(MFC Question) What's the best way to determine the current displayed client area in a CScrollView? I only need the size of the visible portion, so GetClientRect() won't work here.

A: 

Inside your OnDraw() function, you could call pDC->GetViewportOrg and pDC->GetViewportExt.

EDIT: Sorry, I forgot that Viewport extents are only scaling factors. I agree that what you really need here is the client rect.

jeffm
A: 

Thanks, but that won't work. GetViewportExt returns (1,1)

+1  A: 

You do need to use GetClientRect(), but I think you're asking the wrong question. It is not so that in a scrolled view there is a very big client window that is physically scrolled. Instead, when you scroll, the DC's viewportext and mapping mode are adjusted, which make it seem like your view is bigger than it actually is. So, if you want to draw a line from the top left corner of the bottom right corner of the current viewport, you do need GetViewPortOrg() and GetViewportExt(). If these return the wrong values, something is wrong in your use of CScrollView. Did you call SetScrollSizes()?

Roel
A: 

Yep, you're both right. GetClientRect was exactly what I needed. A brain fart on my part...