Announcement

Collapse
No announcement yet.

Progress Bars

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Progress Bars

    I have an encryption app that will use a progress bar to
    display the encryption progress... I'm not really having any
    problems with the progress bar itself. What I'm curious about
    is how a add the written percentage in the middle of the bar,
    like I've seen in so many other apps.

    ------------------

    #2
    I did NOT write this, it was posted up here somewhere so I'm merely passing it along...

    Would the owner of this code please take credit

    Scott
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "WIN32API.INC"
    
       CallBack Function PicProc
          Static Done As Long, hBrush1 As Long, hBrush2 As Long
          Local hDC As Long, LpPaint As PaintStruct
          Local tRect As Rect, hBrush As Long, Clr As Long
          Local i As Long, j As Long, x1 As Long, x2 As Long, hRgn As Long
          Select Case CbMsg
             Case %WM_INITDIALOG
                hBrush1 = CreateSolidBrush(Rgb(  0,   0, 255))
                hBrush2 = CreateSolidBrush(Rgb(255, 255, 255))
             Case %WM_DESTROY
                DeleteObject hBrush1: DeleteObject hBrush2
                InvalidateRect GetParent(CbHndl), ByVal 0, %True
                UpdateWindow GetParent(CbHndl)
             Case %WM_ERASEBKGND: Function = 1: Exit Function
             Case %WM_USER + 1
                Done = CbWparam
                InValidateRect CbHndl, ByVal 0, %True: UpdateWindow CbHndl
             Case %WM_PAINT
                GetClientRect CbHndl, tRect
                hDC = BeginPaint(CbHndl, LpPaint)
                j = tRect.nLeft + (tRect.nRight - tRect.nLeft) * Done * 0.01
                For i = 1 To 2
                   If i = 1 Then x1 = tRect.nLeft: x2 = j: hBrush = hBrush1: Clr = %WHITE _
                            Else x1 = j + 1: x2 = tRect.nRight: hBrush = hBrush2: Clr = %BLACK
                   hRgn = CreateRectRgn (x1, tRect.nTop, x2, tRect.nBottom)
                   SetWindowRgn CbHndl, hRgn, %False
                   FillRect hDC, tRect, hBrush
                   SetBkMode hDC, %TRANSPARENT
                   SetTextColor hDC, Clr
                   DrawText hDC, Str$(Done)+"%", -1, tRect, _
                      %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
                   DeleteObject hRgn
                Next
                EndPaint CbHndl, LpPaint
          End Select
       End Function
    
       CallBack Function DlgProc
          Static Done As Long, hDlg As Long
          Select Case CbMsg
             Case %WM_COMMAND
                If CbCtl = 101 Then
                   Done = 0
                   SetTimer CbHndl, 1, 500, ByVal %Null
                   Dialog New CbHndl, "", 10, 10, 176, 12, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER To hDlg
                   Dialog Show Modeless hDlg Call PicProc
                   Dialog Send hDlg, %WM_USER + 1, Done, 0
                End If
             Case %WM_TIMER
                Done = Done + 5
                If Done > 100 Then Dialog End hDlg: KillTimer CbHndl, 1 Else _
                Dialog Send hDlg, %WM_USER + 1, Done, 0
          End Select
       End Function
    
       Function PbMain
          Local hDlg As Long, hDlg1 As Long
          Dialog New 0, "Progress Bar",,, 200, 80, %WS_SYSMENU To hDlg
          Control Add Button, Hdlg, 101, "Show", 50, 40,100, 14, %BS_DEFAULT
          Dialog Show Modal hDlg Call DlgProc
       End Function
    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎