Attribute VB_Name = "modThread"
Option Explicit
Public Const INFINITE = &HFFFF      '  Infinite timeout
Public Const CREATE_SUSPENDED = &H4

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Public Declare Function SuspendThread Lib "kernel32" (ByVal hThread As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public hThread As Long
Sub StartThread()
Dim ThreadId As Long
    hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf ThreadEntry, ByVal 0&, CREATE_SUSPENDED, ThreadId)
End Sub
Sub StopThread()
If hThread <> 0 Then
    Dim ExitCode As Long
    TerminateThread hThread, ExitCode
    hThread = 0
End If
End Sub
Sub PauseThread()
If hThread <> 0 Then
    SuspendThread hThread
End If
End Sub
Sub PlayThread()
If hThread <> 0 Then
    ResumeThread hThread
End If
End Sub

Sub ThreadEntry()
On Error Resume Next
Dim C As Long
Do
    If C >= ThumbCount Then C = 0
    DoEvents
        RefreshThumb C
    C = C + 1
Loop
End Sub

