-
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?
-
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.
-
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.
-
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
-
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.
-
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.
-
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.
-
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?