I saw one question in "Programming" forum about colors for progress bar.
Because I prefer "own-drawn" progress bar, I decided to post simple sample.
Regions were excluded, because of problems under Win95.
[This message has been edited by Semen Matusovski (edited April 16, 2000).]
Because I prefer "own-drawn" progress bar, I decided to post simple sample.
Code:
#Compile Exe #Register None #Dim All #Include "WIN32API.INC" CallBack Function PicProc Static hBrush() As Long, hDC() As Long, hBmp() As Long, Clr() As Long Static i As Long, Done As Long, LpPaint As PaintStruct, tRect As Rect Static zText As Asciiz * 255 Select Case CbMsg Case %WM_INITDIALOG ReDim hDC(0 To 2): ReDim hBrush(1 To 2): ReDim hBmp(1 To 2): ReDim Clr(1 To 2) hBrush(1) = CreateSolidBrush(Rgb( 0, 0, 255)): Clr(1) = %White hBrush(2) = CreateSolidBrush(Rgb(255, 255, 255)): Clr(2) = %Black Case %WM_DESTROY For i = 1 To 2: DeleteObject hBrush(i): Next 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(0) = BeginPaint(CbHndl, LpPaint) For i = 1 To 2 hDC(i) = CreateCompatibleDC(hDC(0)) hBmp(i) = CreateCompatibleBitMap (hDC(0), tRect.nRight, tRect.nBottom) SelectObject hDc(i), hBmp(i) FillRect hDC(i), tRect, hBrush(i) SetBkMode hDC(i), %TRANSPARENT SetTextColor hDC(i), Clr(i) Select Case Done Case 6 To 12: zText = "A lot of time to sleep" Case 86 To 92: zText = "Wake up, almost done" Case Else: zText = Str$(Done)+"%" End Select DrawText hDC(i), zText, -1, tRect, _ %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER Next BitBlt hDC(2), 0, 0, tRect.nRight * Done * 0.01, tRect.nBottom, hDC(1), 0, 0, %SRCCOPY BitBlt hDC(0), 0, 0, tRect.nRight, tRect.nBottom, hDC(2), 0, 0, %SRCCOPY EndPaint CbHndl, LpPaint For i = 1 To 2: DeleteDC hDC(i): DeleteObject hBmp(i): Next Function = 0: Exit Function 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 + 2 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
[This message has been edited by Semen Matusovski (edited April 16, 2000).]
Comment