dcsimg
September 20, 2020
Hot Topics:

Create a Progress Bar using the API

  • By Sam Huggill
  • Send Email »
  • More Articles »

Add a new form (frmTest) and add six command buttons (cmdBarColour, cmdBackColour, cmdDestroy, cmdCreate, cmdCreateVert and cmdSetVal). Copy the following code into the form:

Option Explicit 
  '// Stores the progress bars window handle   
Private lnghWnd As Long 
 
Private Sub cmdBackColour_Click() 
  '// Set the backcolour   
  SendMessage lnghWnd, SB_SETBKCOLOR, 0, ByVal RGB(255,255, 255) 
End Sub 
 
Private Sub cmdBarColour_Click() 
  '// Set the bar colour   
  SendMessage lnghWnd, PBM_SETBARCOLOR, 0, ByVal RGB(0,127, 0) 
End Sub 
 
Private Sub cmdDestroy_Click() 
  '// Destroy the progress bar   
  DestroyWindow lnghWnd 
End Sub 
 
Private Sub cmdCreate_Click() 
  '// Create a horizontal progress bar   
  CreateProgress False 
End Sub 
 
Private Sub cmdSetVal_Click() 
  '//Set the position to 50   
  SendMessage lnghWnd, PBM_SETPOS, 50, 0 
End Sub 
 
Private Sub cmdCreateVert_Click() 
  '// Create a vertical progress bar   
  CreateProgress True 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
  '// Destroy the progress bar   
  DestroyWindow lnghWnd 
End Sub 
 
Sub CreateProgress(Vertical As Boolean) 
  Dim lngType As Long 
  Dim x As Long 
  Dim y As Long 
  Dim lngHeight As Long 
  Dim lngWidth As Long 

  If Vertical = True Then 
      '// Set the style to vertical   
    lngType = PBS_VERTICAL 
    x = 250 
    y = 25 
    lngHeight = 125 
    lngWidth = 20 
  Else 
    lngType = 0 
    x = 100 
    y = 125 
    lngHeight = 20 
    lngWidth = 125 
  End If 

  '// Create the progress bar   
  lnghWnd = CreateWindowEX(0, PROGRESS_CLASS,"", WS_VISIBLE _
                          Or WS_CHILD Or lngType, 0, 0, 0, 0, Me.hwnd, _
                          0&, App.hInstance, 0&) 
  '// Set the bar's parent   
  Call SetParent(lnghWnd, Me.hwnd) 
  '// Create another window   
  lnghWnd = CreateWindowEX(0, PROGRESS_CLASS,"", WS_VISIBLE _
                           Or WS_CHILD Or lngType, 0, 0, 0, 0, Me.hwnd, _
                           0&, App.hInstance, 0&) 
  '// Move it   
  MoveWindow lnghWnd, x, y, lngWidth, lngHeight, True 
End Sub




Page 3 of 3



This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.


Thanks for your registration, follow us on our social networks to keep up-to-date