Results 1 to 5 of 5

Thread: CreateCompatibleDC question

  1. #1

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219

    CreateCompatibleDC question

    I am loading 2 images (sprite and mask) into DC that I have created using the CreateCompatibleDC api, and then I blit them into the screen. My question is: How do I create another dc so I can blit the new transparent image (result of mask + sprite) into it, and not into the form.

    The code I am using is the following, but it doesn't work, even though I don't get any errors. But is works OK when I blit them into the screen.

    VB Code:
    1. Private Sub Form_Activate()
    2.  
    3. 'Create DC
    4. MaskDC = CreateCompatibleDC(Me.hdc)
    5. SpriteDC = CreateCompatibleDC(Me.hdc)
    6. FinalImageDC = CreateCompatibleDC(Me.hdc)
    7.  
    8. 'Load images
    9. MaskIM = LoadImage(0, "C:\WINDOWS\Desktop\Henrique\Shooter\Images\target_hit_mask.bmp", 0, 0, 0, &H10)
    10. SpriteIM = LoadImage(0, "C:\WINDOWS\Desktop\Henrique\Shooter\Images\target_hit_sprite.bmp", 0, 0, 0, &H10)
    11.  
    12. 'Link DC with image
    13. SelectObject MaskDC, MaskIM
    14. SelectObject SpriteDC, SpriteIM
    15.  
    16. 'Go through each separate part of the images
    17.     Do
    18.        
    19.         DoEvents
    20.         Me.Cls
    21.        
    22.         'This is what does not work, the FinalImageDC
    23.         BitBlt FinalImageDC, 10, 10, 30, 74, MaskDC, x, 0, vbSrcAnd
    24.         BitBlt FinalImageDC, 10, 10, 30, 74, SpriteDC, x, 0, vbSrcPaint
    25.        
    26.         x = x + 31
    27.        
    28.         If x >= 740 Then
    29.             x = 0
    30.         End If
    31.                
    32.     Loop Until GameOver = True
    33. End Sub

    Is this the right way of doing this, or is there another API call for this?

    Thanks

  2. #2
    Megatron
    Guest
    You need to select a bitmap for FinalImageDC. You can do this using the CreateCompatibleBitmap function to create the bitmap, and use SelectObject to attach it to the DC.

  3. #3

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    Sorry to ask you this, but I just lost everything in my computer, and don't have this project...

    Would it be like this?
    VB Code:
    1. FinalImageDC = CreateCompatibleDC(Me.hdc)
    2. FinalImage = CreateCompatibleBitmap(FinalhImageDC, 20, 20)
    3.  
    4. SelectObject FinalImageDC, FinalImage

  4. #4
    Megatron
    Guest
    Yes

  5. #5

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    Thanks

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