Results 1 to 8 of 8

Thread: Bitblt in loop kills my computer

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Question

    This is only a part of my project, but it's one heck important one. I use bitblt to scroll the form content from right to left. Using the timer, it goes to slow so I put it in an infinite loop (that exits on unload attemt). But this hang up everything in this order: Mouseclick not responing, Keybord not responding, Winamp stops playing, Mouse don't move, beeping when moving mouse/keybord(sometimes). I press reset.

    Ok this isn't a nice scenario, but then I put a for next with 10 instead of the infinite loop and it will hang up for about 20 seconds. Slowly starting to run again. (only if you have time to unload it.

    Code:
    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
    
    
    Private Sub Form_Unload(Cancel As Integer)
        If UnloadSequence < 2 Then UnloadSequence = 1: Cancel = 1
    End Sub
    
    Private Sub Timer2_Timer()
        Timer2.Enabled = False
        Do
            BitBlt hDC, 0, 0, ScaleWidth, ScaleHeight, hDC, TextWidth("O") / 15 / 10, 0, vbSrcCopy
            DoEvents
        Loop Until UnloadSequence
        UnloadSequence = 2
        Unload Me
    End Sub
    Ok, people! I want a way to use bitblt as fast as possible without having this kind of problems. Any ideas?
    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.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I had a problem like this too, when I had a go with BitBlt. I was trying to make an image follow the mousepointer while it was clicked. I never had it crash, but I did have it go REAl slow and then have an illegal op and shut down VB. I thought it was just a real slow function.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Unhappy

    Bitblt is damn fast, but my way of doing this, seems to slow down all other processes. It's like while one bitblt process is running, several other must be done not in that little doevents that follows.
    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.

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Lightbulb DoEvents

    DoEvents can slow your loops write down, but unfortunatley you need it there to be able to get out of the loop, or do anything else.

    Seeing as we need DoEvents we can't remove it from the loop, but we can reduce the number of calls made to it.

    Try putting a counter in so that every time you go around the loop it gets incremented by 1.

    Then you can test it against a number of your choice. Say 10 for this example. So DoEvents is only called 1 time in 10 iterations of the loop

    Code:
    Private Sub Timer2_Timer()
        Dim iCounter as Long
    
        Timer2.Enabled = False
        Do
            BitBlt hDC, 0, 0, ScaleWidth, ScaleHeight, hDC, TextWidth("O") / 15 / 10, 0, vbSrcCopy
            
            'increment the loop counter
            iCounter = iCounter + 1
            'If iCounter is a exact multiple of 10 then DoEvents
            If iCounter Mod 10 = 0 Then
              DoEvents
            End If
        Loop Until UnloadSequence
        UnloadSequence = 2
        Unload Me
    End Sub
    Iain, thats with an i by the way!

  5. #5

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Talking

    Aren't you going in the opposite direction? I'm trying to get more doevents, havent tested that yet, but ill try, of course I'll try your example too.
    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.

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    If you want more DoEvents then swap the code around.
    Use DoEvents everytime you go around the loop, and only use BitBlt evert ten times.

    I have no idea what this will do to your program, but in my view everything is worth a go.
    Iain, thats with an i by the way!

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Rather than using bitblt to scroll the form there is an easier way and that is to place all the controls on your form inside of a wide picturebox which itself is inside a form-width picturebox. To "scroll the form" you then just move the wide picturebox within the other picturebox using standard VB. If you want me to send you a demo project please email me. The demo scrolls from top to bottom, but the method is the same.

  8. #8

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Unhappy

    MartinLiss, Im not scrolling any controls here, Im scrolling the picture property of the form. I have tried to use bitblts in loops: same result but it takes less time for system to recover. That's not a solution. Any one have one?
    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