Click to See Complete Forum and Search --> : Backbuffers
Rmch
Oct 21st, 2000, 06:04 PM
Does anyone have advice on how to set up a backbuffer as an interim drawing surface before blitting to the main screen?
I've been playing around with BitBlt but can't seem to get it to do what I want because I don't want the backbuffer visible. I can't find a way to BitBlt from a hidden form or picture for example.
Is there a way to assign the hdc of the source bitmap to some structure or something and copy the .image there?
kedaman
Oct 21st, 2000, 07:21 PM
Yep, i think you should use CreateCompatiblebitmap to make the backbuffer and then use createcompatibleDC to create your device context, then selectobject the bitmap and you can start backbuffering to the bitmap
'In declarations:
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Backbuffer As Long
'In code
Backbuffer = CreateCompatibleDC(hdc)
SelectObject Backbuffer, CreateCompatibleBitmap(hdc, 800, 600)
Rmch
Oct 21st, 2000, 07:39 PM
Thanks. I'll give it a whirl and let you know how it goes :)
Rmch
Oct 22nd, 2000, 11:51 AM
So far it works great. Do I need to delete the DC after I'm done with the buffer?
Many times I have to break the program. Just wondering if that causes housecleaning problems.
kedaman
Oct 22nd, 2000, 12:51 PM
Yeah, sorry about that, forgot to tell you :)
both the DC and the bitmap needs to be removed after use:
'Declarations
Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Function GetBitmap(hDC As Long) As Long
Dim hBitmap As Long
hBitmap = CreateCompatibleBitmap(hDC, 0, 0) 'Creates a dummy bitmap
hBitmap = SelectObject(hDC, hBitmap) 'swaps the new bitmap with the bitmap in the DC
DeleteObject SelectObject(hDC, hBitmap) 'puts the bitmap back and deletes the one we created
GetBitmap = hBitmap
End Function
'To delete the dc with the bitmap
DeleteObject GetBitmap(BackBuffer)
DeleteDc Backbuffer
'You could also delete the bitmap if you have it's handle stored, then you don't haveto use getbitmap, which is a bit roundabout way
[/code]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.