tags:

views:

33

answers:

2

I'm trying to retrieve the entire rectangle of a scrollable window using the WIN32 API. I thought that GetClientRect would return what I need, but that function appears to return only the current viewport. Is there a specific function call that returns the entire scrollable region as a RECT or must I call GetScrollRange to calculate the region myself?

+2  A: 

It sounds as if that particular window is using virtual scrolling. Even GetScrollRange doesn't necessarily tell you the dimensions, because there's no requirement that a delta of 1 on the scrollbar equals 1 pixel, in fact in many cases it is one record, one row, etc.

Another thing to try is to enumerate all the child windows, and find the minimum and maximum x and y coordinates (don't forget to include the width and height of each child window). Of course this won't help if the content is directly drawn and not a hierarchy of windows.

Ben Voigt
+3  A: 

It doesn't work like that. As far as Windows is concerned, a scrollable window isn't a small viewport onto a larger region whose dimensions you can set or retrieve, it's just a rectangle with a scroll bar control at the edge. It's up to you to determine the appearance of the scroll bar by calculating the portion of the notional region that is visible within the viewport provided by the window, and to paint the window contents accordingly.

Brian Nixon
Ah, thanks for the explanation, now it makes sense. I was under the mistaken impression that the client area was essentially a viewport into a larger region, as in your example.
Emerick Rogul
Actually, there are several possibilities, from a viewport onto a larger region (a single large child control which is moved around), a viewport onto a larger region (many children all of which move in concert), a virtual viewport (child controls are created/destroyed as they come into view), a canvas (drawing occurs within the active area), or a scrollbar can be just a slider input control that doesn't scroll anything.
Ben Voigt
@Ben - Are you talking about Win32? Doesn't sound like it.
Heath Hunnicutt
Yes. See for example ScrollWindowEx which can be used to implement the bulk of the logic for the first two patterns I mentioned. Note that the larger "content" window is a child of the "viewport" window.
Ben Voigt