Results 1 to 4 of 4

Thread: Scrolling Picture?

  1. #1

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126

    Question

    How do I make a picture look like it scrolls inside picturebox?

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Here is the simplest way you can also use the BitBlt API to make it faster...

    Code:
    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.
    Last edited by YoungBuck; Feb 2nd, 2001 at 11:10 PM.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    BitBlt and Offscreen DC method

    Code:
    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
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    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

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