views:

156

answers:

2
+3  Q: 

GDI fast scroll

Hi!

I use GDI to create some custom textwidget. I draw directly to the screen, unbuffered.

now i'd like to implement some fast scrolling, that simply pixelshifts the respective part of the framebuffer (and only redraws the newly visible lines).

I noticed that for example the rich text controls does it like this. If i use some GDI drawing functions to directly draw to the framebuffer, over a rich text control, and then scroll the rich text, it will also scroll my drawing along with the text. so i assume the rich text simply pixelshifts it's part of the framebuffer.

I'd like to do the same, but don't know how to do so.

Can someone help? (independant of programming language))

thanks!

+2  A: 

See BitBlt function:

The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

and the example at the end of its documentation: Capturing an Image:

You can use a bitmap to capture an image, and you can store the captured image in memory, display it at a different location in your application's window. [...] In some cases, you may want your application to capture images and store them only temporarily. [...] To store an image temporarily, your application must call CreateCompatibleDC to create a DC that is compatible with the current window DC. After you create a compatible DC, you create a bitmap with the appropriate dimensions by calling the CreateCompatibleBitmap function and then select it into this device context by calling the SelectObject function.

After the compatible device context is created and the appropriate bitmap has been selected into it, you can capture the image. The BitBlt function captures images. This function performs a bit block transfer that is, it copies data from a source bitmap into a destination bitmap. [...] To redisplay the image, call BitBlt a second time, specifying the compatible DC as the source DC and a window DC as the target DC.

Bill
`BitBlt` would require two blit operators. One to move pixels to a temporary buffer and another to move them back to the original at the new location. With `ScrollDC` you can move pixels in a DC in a single move.
Adrian McCarthy
+6  A: 

The ScrollWindowEx() API function is optimized to do this.

Hans Passant
Wow, didn't know about that. :)
Matteo Italia
hey!Thanks a lot for that!But is there also a function that allows to operate on the framebuffer directly? the problem is that i'm working on a framework that has an abstraction layer which does not allow me to access the window handle - however, i know exact position and size on screen and i can make windows API calls
genesys
Hmm, that's not going to work. What ever you update will be wiped out by the window repainting itself.
Hans Passant
You can always specify a handle to the desktop window and provide as scrolling rectangle only the client area of your window, but I'm not sure if it's going to work.
Matteo Italia
`ScrollDC()` lets you accomplish approximately the same thing without a window handle.
Adrian McCarthy