CyberCarsten
Oct 25th, 2001, 02:18 PM
Hi guys!
I'm trying to move a picture using BitBlt to avoid flickering.
I have got the picture to move both to the left and to the right, but when it moves to the right, it leaves some kind of trail....why is that???
Also, how can make a picture transparent...meaning how do i only show, ie. if the picture is a ball, the ball and not the background??
Source:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim x As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyRight) Then
GoRight
End If
If GetAsyncKeyState(vbKeyLeft) Then
GoLeft
End If
End Sub
Public Sub GoRight()
x = x + 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh
End Sub
Public Sub GoLeft()
x = x - 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh
End Sub
Module:
' ********************************************************************
' Project : BitBltPrimer.vbp
' Filename : BitBlt.bas
' Description : BitBlt API primer tutorial project
' Created : 11.15 PM GMT + 10.00, February 23, 1998
' Modified : 12:26 AM GMT + 10.00, October 17, 1998
' ********************************************************************
' Author : Michael Lambino
' E-mail : ProSoft@the18th.com
' Comments : Copyright ©, 23 February, 1998, Michael Lambino
' License : Freeware - Freely distributable unmodified.
' : No costs may be charged whatsoever for the
' : distribution of this tutorial, in any form of
' : media, without expressed permission of the author.
' ********************************************************************
' Require all variables be declared.
Option Explicit
' Enumerated raster operation constants
Public Enum RasterOps
'
' Copies the source bitmap to destination bitmap
SRCcopy = &HCC0020
'
' Combines pixels of the destination with source bitmap using
' the Boolean AND operator.
SRCAND = &H8800C6
'
' Combines pixels of the destination with source bitmap using
' the Boolean XOR operator.
SRCinvert = &H660046
'
' Combines pixels of the destination with source bitmap using
' the Boolean OR operator.
SRCpaint = &HEE0086
'
' Inverts the destination bitmap and then combines the results
' with the source bitmap using the Boolean AND operator.
SRCERASE = &H4400328
'
' Turns all output white.
WHITENESS = &HFF0062
'
' Turn output black.
BLACKNESS = &H42
End Enum
' BitBlt API Public Declaration
Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As RasterOps _
) As Long
' ********************************************************************
' Parameter descriptions
' ********************************************************************
' ByVal hDestDC As Long : hDC of object (Destination PictureBox hDC)
' : in which resulting Blt operation will
' : performed.
' ----------------------+---------------------------------------------
' ByVal x As Long : Leftmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal y As Long : Topmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal nWidth As Long : Width of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal nHeight As Long : height of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal hSrcDC As Long : hDC of object (Source PictureBox hDC) in
' : which resulting Blt operation will be
' : performed from.
' ----------------------+---------------------------------------------
' ByVal xSrc As Long : Leftmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal ySrc As Long : Topmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal dwRop As Long : specifies the raster operation to be
' : performed as above.
' --------------------------------------------------------------------
I'm trying to move a picture using BitBlt to avoid flickering.
I have got the picture to move both to the left and to the right, but when it moves to the right, it leaves some kind of trail....why is that???
Also, how can make a picture transparent...meaning how do i only show, ie. if the picture is a ball, the ball and not the background??
Source:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim x As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyRight) Then
GoRight
End If
If GetAsyncKeyState(vbKeyLeft) Then
GoLeft
End If
End Sub
Public Sub GoRight()
x = x + 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh
End Sub
Public Sub GoLeft()
x = x - 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh
End Sub
Module:
' ********************************************************************
' Project : BitBltPrimer.vbp
' Filename : BitBlt.bas
' Description : BitBlt API primer tutorial project
' Created : 11.15 PM GMT + 10.00, February 23, 1998
' Modified : 12:26 AM GMT + 10.00, October 17, 1998
' ********************************************************************
' Author : Michael Lambino
' E-mail : ProSoft@the18th.com
' Comments : Copyright ©, 23 February, 1998, Michael Lambino
' License : Freeware - Freely distributable unmodified.
' : No costs may be charged whatsoever for the
' : distribution of this tutorial, in any form of
' : media, without expressed permission of the author.
' ********************************************************************
' Require all variables be declared.
Option Explicit
' Enumerated raster operation constants
Public Enum RasterOps
'
' Copies the source bitmap to destination bitmap
SRCcopy = &HCC0020
'
' Combines pixels of the destination with source bitmap using
' the Boolean AND operator.
SRCAND = &H8800C6
'
' Combines pixels of the destination with source bitmap using
' the Boolean XOR operator.
SRCinvert = &H660046
'
' Combines pixels of the destination with source bitmap using
' the Boolean OR operator.
SRCpaint = &HEE0086
'
' Inverts the destination bitmap and then combines the results
' with the source bitmap using the Boolean AND operator.
SRCERASE = &H4400328
'
' Turns all output white.
WHITENESS = &HFF0062
'
' Turn output black.
BLACKNESS = &H42
End Enum
' BitBlt API Public Declaration
Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As RasterOps _
) As Long
' ********************************************************************
' Parameter descriptions
' ********************************************************************
' ByVal hDestDC As Long : hDC of object (Destination PictureBox hDC)
' : in which resulting Blt operation will
' : performed.
' ----------------------+---------------------------------------------
' ByVal x As Long : Leftmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal y As Long : Topmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal nWidth As Long : Width of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal nHeight As Long : height of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal hSrcDC As Long : hDC of object (Source PictureBox hDC) in
' : which resulting Blt operation will be
' : performed from.
' ----------------------+---------------------------------------------
' ByVal xSrc As Long : Leftmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal ySrc As Long : Topmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal dwRop As Long : specifies the raster operation to be
' : performed as above.
' --------------------------------------------------------------------