Results 1 to 12 of 12

Thread: Color Change

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Ireland, Dublin
    Posts
    76

    Color Change

    Does anyone know how to change the colour of a Progress Bar.

    Regards

    IJ...
    ---------------------------------
    TopMan
    ---------------------------------

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Make your own? Fancier ones exist at www.planetsourcecode.com

    By Mark Sreeves

    Code:
    Private Sub Command1_Click()
    Static i As Integer
    i = i + 1
    UpdateProgress i
    End Sub
    
    Private Sub Form_Load()
    Picture1.Tag = 100
    Picture1.BackColor = 12582912 'change To whatever
    End Sub
    Private Sub UpdateProgress(ByVal iValue As Long)
    On Error Resume Next
        With Picture1
            If iValue = 1 Then .Cls
            Picture1.Line (0, 0)-Step((.ScaleWidth / .Tag) * iValue, .ScaleHeight), &HFF&, BF      'vbActiveTitleBar
        End With
        
    End SubstFile = stDir1 & stFile 
    FileCopy stFile, stDir2 & sNewFile 
    sCounter = sCounter + 1 
    ProgressBar1.Value = sCounter 
    stFile = Dir 
    Next x 
    
    End Sub 
    
    Private Sub Form_Load() 
    ProgressBar1.Max = 10 
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Ireland, Dublin
    Posts
    76
    Thanks,

    But I want to know how to change the Progress Bar's colour.
    Can it be done ?

    Cheers,

    IJ...
    ---------------------------------
    TopMan
    ---------------------------------

  4. #4
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias _
    2. "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    3. ByVal wParam As Long, lParam As Any) As Long
    4.    
    5. Private Const WM_USER = &H400
    6. Private Const PBM_SETBARCOLOR = WM_USER + 9
    7. Private Const PBM_SETBKCOLOR = &H2000 + 1
    8.  
    9. Public Function SetPBBackColor(ProgressBar As Object, _
    10.    NewColor As OLE_COLOR) As Boolean
    11.  
    12. On Error Resume Next
    13. Dim lRet As Long
    14. lRet = SendMessage(ProgressBar.hwnd, PBM_SETBKCOLOR, 0&, NewColor)
    15.  
    16. End Function
    17.  
    18. Public Function SetPBBarColor(ProgressBar As Object, _
    19.    NewColor As OLE_COLOR) As Boolean
    20.  
    21. On Error Resume Next
    22. Dim lRet As Long
    23. lRet = SendMessage(ProgressBar.hwnd, PBM_SETBARCOLOR, 0&, NewColor)
    24.  
    25. End Function
    26.  
    27.  
    28. [b][u]Usage[/u][/b]
    29.  
    30. SetPBBackColor ProgressBar1, vbRed

  5. #5
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Constants

    Alright guys,

    I know how SendMessage function works, but how do you find the correct constants (messages) to send to each control ???? I have SOME listed but where do you get all of them ???

    MSDN didn't help me much.

    If anyone has a link or anything, please report..


    Thanks,
    Hyperspaced

  6. #6
    Matthew Gates
    Guest
    To get a list of API functions and constants, go to http://www.vbapi.com and download the API-Guide and the API-ToolShed.

  7. #7
    Megatron
    Guest
    API-ToolShed has the constants, and API-guide has the documentation of the functions.

  8. #8
    jim mcnamara
    Guest
    API ToolShed & Guide are great but Megatron neglected to mention they are found at


    allapi.net

  9. #9
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Hmmmmmmmmm..............

    Hmmmmmmmmmmmmmm, that's how you raise the counter....

    hehehehehe... (just kidding of course ;-))))))))))))))))))) )

  10. #10
    Megatron
    Guest
    Originally posted by jim mcnamara
    API ToolShed & Guide are great but Megatron neglected to mention they are found at[/URL]
    I was posting a follow up to Matthew Gates's response. (I presumed that he posted the right link)

  11. #11
    Matthew Gates
    Guest
    My bad, I meant http://www.allapi.net, sorry about that Megatron and jim mcnamara .

  12. #12
    Lively Member Ceri's Avatar
    Join Date
    Sep 2000
    Posts
    72

    Little Mistake...

    Mathew - I belive you have missed out the 'ByVal' on the SendMessage call on the above example :-

    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias _
    2. "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    3. ByVal wParam As Long, lParam As Any) As Long
    4.    
    5. Private Const WM_USER = &H400
    6. Private Const PBM_SETBARCOLOR = WM_USER + 9
    7. Private Const PBM_SETBKCOLOR = &H2000 + 1
    8.  
    9. Public Function SetPBBackColor(ProgressBar As Object, _
    10.    NewColor As OLE_COLOR) As Boolean
    11.  
    12. On Error Resume Next
    13. Dim lRet As Long
    14. lRet = SendMessage(ProgressBar.hwnd, PBM_SETBKCOLOR, 0&, [B]ByVal[/B] NewColor)
    15.  
    16. End Function
    17.  
    18. Public Function SetPBBarColor(ProgressBar As Object, _
    19.    NewColor As OLE_COLOR) As Boolean
    20.  
    21. On Error Resume Next
    22. Dim lRet As Long
    23. lRet = SendMessage(ProgressBar.hwnd, PBM_SETBARCOLOR, 0&, [B]ByVal[/B] NewColor)
    24.  
    25. End Function

    just in case you missed it, I thought i'd put it in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width