Click to See Complete Forum and Search --> : Scrolling user-drawn bitmaps?


Volkan
April 13th, 1999, 02:44 PM
Is there some way to bitblt a bitmap to the "virtual" window that is under the viewable area when scrollbars are active?

In other words.. my bitmap is always displayed at the same location in my window no matter where the scrollbars (thumbs) are.

Can someone tell me how I can display a partial bitmap (or no bitmap) based on how much the window has been scrolled?

Any help would be GREATLY appreciated.

Saurabh Dasgupta
April 14th, 1999, 07:51 AM
Hi,
When you are using scroll bars, you must be careful to translate your window positions. Let me make it simple, your drawing on a big canvas ( a very big one) and you monitor size is such that you can view only a small portion of it. graphics to a new point x,y .This x,y is obtained from the current scrollbar So what do you do ? To view any part of the canvas, you place your window over that part of the canvas. And this you do using hor. and vert. scrollbars. Dragging the scrollbars is like dragging the view window to a new location.

So when you are refreshing your graphics, you obtain the scroll bar positions x,y. Set the origin of the device context (hdc) to x,y using the API
SetWindowOrgEx(hdc, x, y, NULL). (assuming that you have set the scroll ranges judiciously)

Now you have translated your origin to x,y. If you try placing a point at the location x,y then you will actually see a point appearing at 0,0.
Finally the most important thing, you need to handle the WM_HSCROLL & WM_VSCROLL messages. In the handler for these messages you need to scroll the window contents by using the API ScrollWindowEx, update the window immediately, so that the portions of the image that have just come into the user's view gets redrawn. For optimized performance you should be updating the a very small portion of the window. Example:you have scrolled the window by an amount 5 units to the right, assume the height of the window to be H units. So a rectangle of dimension 5 units X H units from the left side of the window has become visile to the user, and only this rectangle needs to be invalidated(InvalidateRect)

This should work. The important issues here are: how you set the range of the scroll bar(s), by what amount will you be scrolling each time, and what happens when the user re-sizes the window. At times you may not need to have a scroll bar at all. For further information please refer the DIBAPI sample in the samples\sdk\win32 sub-directory of MSVC50 product.

Regards
Saurabh