Attribute VB_Name = "hlp_ctProgressB"
' modul for Visual Basic 6
' Copyright (C) 2004-2006 Jan Vorel

' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' This is a shared modul, class modul, usercontrol or form. It is also
' published under the GNU General Public License.

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

Option Explicit
Option Base 0

' Please do not use the "Remove integer overflow checks" compiler options when using this module!

'Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function SendMessageA Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function CreateWindowExA Lib "user32" (ByVal dwExStyle As Long, ByVal lpClassName As String, 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, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Sub ctProgressB_SetValue(ByVal ProgressControl As Long, ByVal ProgressPosition As Long, ByVal ProgressTotal As Long)
  Static xLong1 As Long
  Static xChar1 As String
    
  If Not (ProgressControl = 0& Or ProgressTotal = 0&) Then
    xLong1 = CLng(CInt(ProgressPosition / ProgressTotal * 100))
    xChar1 = Trim(Str(CInt(ProgressPosition / ProgressTotal * 10000) / 100 + 0.001))
    xChar1 = Left(xChar1, Len(xChar1) - 1) & "%"
    If ProgressPosition / ProgressTotal < 0.01 Then xChar1 = "0" & xChar1
    Call SendMessageA(ProgressControl, 1026&, ByVal xLong1, ByVal 0&)
    Call SendMessageA(ProgressControl, 12&, ByVal 0&, ByVal xChar1)
    DoEvents
    End If
  End Sub

Public Function ctProgressB_Create(ByVal ParentHwnd As Long, ByVal Left As Long, ByVal Top As Long, ByVal Width As Long, Optional ByVal Height As Long = 17&) As Long
  ctProgressB_Create = CreateWindowExA(512&, "msctls_progress32", "", &H50000001, Left, Top, Width, Height, ParentHwnd, vbNull, App.hInstance, ByVal 0&)
  End Function

