Results 1 to 5 of 5

Thread: Backbuffers

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    5

    Unhappy

    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?


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Code:
    '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)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    5

    Thumbs up Very cool.

    Thanks. I'll give it a whirl and let you know how it goes

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    5

    One more question.

    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.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah, sorry about that, forgot to tell you
    both the DC and the bitmap needs to be removed after use:
    Code:
    '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]
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width