Visual Basic > API and Miscellaneous
Creating A Percentage Done Status Display
Creating A Percentage Done Status Display 'This is the API we will be using. Private Declare Function BitBlt Lib "GDI32" _ (ByVal hDestDC As Integer, ByVal X As Integer, _ ByVal Y As Integer, ByVal nWidth As Integer, _ ByVal nHeight As Integer, ByVal hSrcDC As Integer, _ ByVal XSrc As Integer, ByVal YSrc As Integer, _ ByVal dwRop As Long) As Integer 'Dimension a variable. Dim tenth As Long 'This function updates the status bar by a 'certain amount (specified as a perecntage). Sub UpdateStatus(Amount As Long) 'Dimension some variables. Static progress As Long Const SRCCOPY = &HCC0020 Dim Txt$ 'Update the status bar. progress = progress + Amount If progress > Picture1.ScaleWidth Then progress = Picture1.ScaleWidth End If Txt$ = Format$(CLng((progress / Picture1.ScaleWidth) * 100)) + "%" Picture1.Cls Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth(Txt$)) \ 2 Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight(Txt$)) \ 2 Picture1.Print Txt$ Picture1.Line (0, 0)-(progress, Picture1.ScaleHeight), Picture1.ForeColor, BF r = BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _ Picture1.hDC, 0, 0, SRCCOPY) End Sub Private Sub Form_Load() Picture1.AutoRedraw = True Picture1.BackColor = &H80000003 Picture1.DrawMode = 10 Picture1.FillStyle = 0 Picture1.ForeColor = &H80 End Sub Private Sub Command1_Click() Picture1.ScaleWidth = 109 tenth = 10 For i = 1 To 11 Call UpdateStatus(tenth) X = Timer While Timer < X + 0.75 DoEvents Wend Next End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows