[API]
CreateWindowExA
CreateWindowExW
LoadCursorA
DefWindowProcA
DefWindowProcW
RtlMoveMemory
DestroyWindow

[INCLUDE]
DrawProgressBar
RegisterClassEx
GetWindowLong
SetWindowLong
GetWindowText
SetWindowText

[DEFINE]
Private ProgressBar_NumCtls As Long
Private Const ProgressBar_ClassName As String = "ProgressBar"

[CODE]
Public Function ProgressBar_Create(ByVal dwExStyle As Long, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long)
  Dim xType1 As WNDCLASSEX
  
  If ProgressBar_NumCtls = 0& Then
    With xType1
      .cbSize = 48&
      .Style = &H83&
      .hInstance = App.hInstance
      .hCursor = LoadCursorA(App.hInstance, &H7F00&)
      .hbrBackground = 19&
      .ClassName = ProgressBar_ClassName
      .cbWndExtra = 8&
      End With
    Call RegisterClassEx(xType1, AddressOf ProgressBar_Proc)
    End If
  If IsUnicode Then
    ProgressBar_Create = CreateWindowExW(dwExStyle, ByVal StrPtr(ProgressBar_ClassName), ByVal StrPtr(lpWindowName), dwStyle, x, y, nWidth, nHeight, hWndParent, 0&, App.hInstance, ByVal 0&)
    Else
    ProgressBar_Create = CreateWindowExA(dwExStyle, ProgressBar_ClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, 0&, App.hInstance, ByVal 0&)
    End If
  If Not ProgressBar_Create = 0& Then
    Call ProgressBar_Draw(ProgressBar_Create)
    End If
  End Function

Private Sub ProgressBar_Draw(ByVal hwnd As Long)
  Dim xLong1 As Long
  Dim xSingle1 As Single
  
  xLong1 = GetWindowLong(hWnd, 4&)
  If Not xLong1 = 0& Then
    Call RtlMoveMemory(ByVal VarPtr(xSingle1), ByVal VarPtr(xLong1), 4&)
    End If
  Call DrawProgressBar(hwnd, xSingle1, GetWindowText(hwnd))
  End Sub

Public Sub ProgressBar_SetStatus(ByVal hwnd As Long, ByVal Progress As Single, ByVal xText As String, Optional ByVal RedrawNow As Boolean = True)
  Dim xLong1 As Long
  
  Call RtlMoveMemory(ByVal VarPtr(xLong1), ByVal VarPtr(Progress), 4&)
  Call SetWindowLong(hWnd, 4&, xLong1)
  Call SetWindowText(hwnd, xText)
  If RedrawNow Then
    Call DrawProgressBar(hwnd, Progress, xText)
    End If
  End Sub

Private Function ProgressBar_Proc(ByVal hwnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case message
    Case &H14&
    Case &H30&
      Call SetWindowLong(hWnd, 0&, wParam)
      If Not lParam = 0& Then
        Call SendMessage(hWnd&, &HF&, 0&, 0&)
        End If
    Case &H31&
      ProgressBar_Proc = GetWindowLong(hWnd, 0&)
    Case &HF& ', &H14& 'WM_PAINT = &HF
      If IsUnicode Then
        ProgressBar_Proc = DefWindowProcW(hwnd, message, wParam, lParam)
        Else
        ProgressBar_Proc = DefWindowProcA(hwnd, message, wParam, lParam)
        End If
      Call ProgressBar_Draw(hwnd)
      'Exit Function
    Case Else
      If IsUnicode Then
        ProgressBar_Proc = DefWindowProcW(hwnd, message, wParam, lParam)
        Else
        ProgressBar_Proc = DefWindowProcA(hwnd, message, wParam, lParam)
        End If
    End Select
  End Function

Public Function ProgressBar_Destroy(ByVal hwnd As Long)
  Call DestroyWindow(hwnd)
  If ProgressBar_NumCtls = 0& Then
    Call UnregisterClass(ProgressBar_ClassName)
    End If
  End Function
