PDA

Click to See Complete Forum and Search --> : Scrolling Picture?


Spie
Feb 2nd, 2001, 08:40 PM
How do I make a picture look like it scrolls inside picturebox?

YoungBuck
Feb 2nd, 2001, 09:59 PM
Here is the simplest way you can also use the BitBlt API to make it faster...



Dim iPic As IPictureDisp
Dim bEnd As Boolean

Private Sub Form_Load()

Set iPic = LoadPicture("C:\Windows\Bubbles.bmp")

Picture1.AutoRedraw = True

End Sub

Private Sub Picture1_Click()
Dim x As Long

Do Until bEnd = True

If x > Picture1.Width + 1 Then x = 0

Picture1.Cls

Picture1.PaintPicture iPic, x, 0

x = x + 3

DoEvents

Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

set iPic = Nothing

bEnd = True

End Sub



I'll post the BitBlt way in a few minutes.

YoungBuck
Feb 2nd, 2001, 10:11 PM
Option Explicit

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private 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 Long) As Long

Dim lngBackBuffer As Long
Dim lngOrigBMP As Long
Dim iPic As IPictureDisp
Dim bEnd As Boolean

Private Sub Form_Load()

' retrieve handle to the backbuffer device
lngBackBuffer = CreateCompatibleDC(Me.hdc)

' load the image
Set iPic = LoadPicture("C:\Windows\Bubbles.bmp")

' load the image into the backbuffer and retrieve handle of bitmap created with _
device
lngOrigBMP = SelectObject(lngBackBuffer, iPic)

Picture1.AutoRedraw = True

End Sub

Private Sub Picture1_Click()
Dim x As Long

'run animation loop until program ends
Do Until bEnd = True

If x > Me.ScaleX(Picture1.Width, vbTwips, vbPixels) Then x = 0

' clear the picture box
Picture1.Cls

' show the backbuffer
BitBlt Picture1.hdc, x, 0, Me.ScaleX(iPic.Width, vbHimetric, vbPixels), _
Me.ScaleY(iPic.Height, vbHimetric, vbPixels), lngBackBuffer, _
0, 0, vbSrcCopy

x = x + 3

DoEvents

Loop

End Sub

Private Sub Form_Unload(Cancel As Integer)

' load the original bitmap back into Device
SelectObject lngBackBuffer, lngOrigBMP

' remove picture from memory
Set iPic = Nothing

'remove back buffer from memory
DeleteDC lngBackBuffer

bEnd = True

End Sub

Spie
Feb 2nd, 2001, 10:16 PM
Is there some way to connect the picture..to form a tile. I'm trying to create the illusion that the character is moving, when, in reality, it is just the background:)