Results 1 to 9 of 9

Thread: simpLe animation, hangs on unload ; * )

Threaded View

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    simpLe animation, hangs on unload ; * )

    Save a BMP (any, for a test, spIN.bmp) and run the code below. The animation plays but.. when you press the x (not stop in VB IDE). The animation does not close, it hangs still pLaying and your forced to end task.. but why~?

    VB Code:
    1. 'Sonikku`s cOde-_-
    2. Option Explicit
    3. Dim DX As New DirectX7
    4. Dim DD As DirectDraw7
    5. Dim ddsd1 As DDSURFACEDESC2
    6. Dim ddsd2 As DDSURFACEDESC2
    7. Dim Primary As DirectDrawSurface7
    8. Dim PiCBuFFeR As DirectDrawSurface7
    9. Dim bInit As Boolean
    10. Dim brunning As Boolean, brestore As Boolean
    11. Dim ddclipper As DirectDrawClipper
    12.  
    13. Private Type AnimationFrame
    14.     Top As Long
    15.     Left As Long
    16. End Type
    17. Dim Frame(4) As AnimationFrame
    18. Dim CurFrame As Integer
    19. Dim Dir_up As Boolean
    20. Dim LastTimeDrawn As Long
    21. Const Delaytime = 1000 / 25
    22.  
    23. Private Sub Form_load()
    24.     Init
    25. End Sub
    26.  
    27. Sub Init()
    28.     Set DD = DX.DirectDrawCreate("")
    29.     Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
    30.     ddsd1.lFlags = DDSD_CAPS
    31.     ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
    32.        
    33.     Set Primary = DD.CreateSurface(ddsd1)
    34.     ddsd2.lFlags = DDSD_CAPS
    35.     ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    36.        
    37.     Set PiCBuFFeR = DD.CreateSurfaceFromFile("SpIN.bmp", ddsd2)
    38.     CreateLookUpTable
    39.    
    40.     Set ddclipper = DD.CreateClipper(0)
    41.     ddclipper.SetHWnd picbox.hWnd
    42.     Primary.SetClipper ddclipper
    43.        
    44. bInit = True
    45. brunning = True
    46. bLt
    47. End Sub
    48.  
    49. Sub EndiT()
    50.     DD.RestoreDisplayMode
    51.     brunning = False
    52.     End
    53. End Sub
    54.  
    55. Private Sub Form_Resize()
    56.     picbox.Height = Me.ScaleHeight
    57.     picbox.Width = Me.ScaleWidth
    58.     Do While brunning = True
    59.         DoEvents
    60.         bLt
    61.         DoEvents
    62.     Loop
    63. End Sub
    64.  
    65. Sub bLt()
    66.     Dim ddrval As Long
    67.     Dim r1 As RECT
    68.     Dim r2 As RECT
    69.     Call DX.GetWindowRect(picbox.hWnd, r1)
    70.  
    71.     r2.Top = Frame(CurFrame).Top
    72.     r2.Left = Frame(CurFrame).Left
    73.     r2.Bottom = r2.Top + 31
    74.     r2.Right = r2.Left + 31
    75.    
    76.     If DX.TickCount >= LastTimeDrawn + Delaytime Then
    77.         LastTimeDrawn = DX.TickCount
    78.  
    79.         If Dir_up = True Then
    80.             CurFrame = CurFrame + 1
    81.             If CurFrame = 5 Then
    82.  
    83.                 CurFrame = 0
    84.                 Dir_up = True
    85.             End If
    86.         Else
    87.             CurFrame = CurFrame - 1
    88.             If CurFrame = -1 Then
    89.                 CurFrame = 0
    90.                 Dir_up = True
    91.             End If
    92.         End If
    93.     End If
    94.     DoEvents
    95.     ddrval = Primary.bLt(r1, PiCBuFFeR, r2, DDBLT_WAIT)
    96. End Sub
    97.  
    98. Sub CreateLookUpTable()
    99.     Frame(0).Top = 0: Frame(0).Left = 0
    100.     Frame(1).Top = 0: Frame(1).Left = 31
    101.     Frame(2).Top = 0: Frame(2).Left = 62
    102.     Frame(3).Top = 0: Frame(3).Left = 93
    103.     Frame(4).Top = 0: Frame(4).Left = 124
    104. End Sub
    105.  
    106. Private Sub Form_Unload(Cancel As Integer)
    107.     EndiT
    108. End Sub
    109.  
    110. Private Sub Picbox_Paint()
    111.     DD.RestoreAllSurfaces
    112.     Init
    113.     bLt
    114. End Sub
    Last edited by scr0p; Mar 6th, 2003 at 07:31 PM.
    asdf

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