CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    Talking SendMessage and progress bar colors

    Now, I'm trying to change the bar color and background color of a progress bar in VB.
    The way to do this is to send the PBM_SETBARCOLOR and PBM_SETBKCOLOR to the progress bar.
    I coded :
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_USER = &H400
    Private Const PBM_SETBARCOLOR = (WM_USER + 9)
    Private Const CCM_FIRST = &H2000
    Private Const CCM_SETBKCOLOR = (CCM_FIRST + 1)
    Private Const PBM_SETBKCOLOR = CCM_SETBKCOLOR
    
    //command button......when clicked, fill progress bar
    Private Sub cmdGo_Click()
    
    Dim i As Integer
    For i = 0 To 100
        ProgressBar1.Value = i
    Next i
    
    End Sub
    
    Private Sub Form_Load()
    
    'suppose to be black for progress bar's backgound
    SendMessage ProgressBar1.hwnd, PBM_SETBKCOLOR, _
    0, RGB(0, 0, 0)
    'suppose to be yellow for progress bar's bar
    'color
    SendMessage ProgressBar1.hwnd, PBM_SETBARCOLOR, _
    0, RGB(255, 255, 0)
    
    End Sub
    But for some reasons, the color of both the bar and background of the progress bar always seems to be bright yellowish-green, despite the many different colors I set! Why?
    Does anyone have any idea? I've attached the project to this thread.

    Please and thanks a lot!
    Attached Files Attached Files
    "Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria

    "I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria

  2. #2
    Join Date
    May 2002
    Posts
    40

    Re: SendMessage and progress bar colors

    Try this code :
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Sub cmdBackColor_Click()
    ' Change background color  
        On Error GoTo errHandler
    
        With CommonDlg
            .CancelError = True
            'Show common dialog box
            .ShowColor
            ' Change to selected background color
            SendMessage ProgressBar1.hwnd, 8193, 0, ByVal .Color
        End With
    
    Exit Sub
    errHandler:
    End Sub
    
    Private Sub cmdForeColor_Click()
    ' Change foreground color  
        On Error GoTo errHandler
        
        With CommonDlg
            .CancelError = True
            'Show common dialog box
            .ShowColor
            ' Change to selected foreground color
            SendMessage ProgressBar1.hwnd, 1033, 0, ByVal .Color
        End With
        
    Exit Sub
    errHandler:
    End Sub
    
    Private Sub Timer1_Timer()
    
        If ProgressBar1.Value >= ProgressBar1.Max Then ProgressBar1.Value = ProgressBar1.Min
    
        ProgressBar1.Value = ProgressBar1.Value + 1
    
    End Sub
    Efi

  3. #3
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    Talking

    Thanks a lot, Efi!

    But what does the '1033' and '8193' means in this case?
    Thanks a lot!
    "Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria

    "I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria

  4. #4
    Join Date
    May 2002
    Posts
    40
    This is the big ''secret''

    Private Const WM_USER = &H400
    ' 1024 is the Decimal value of &H400

    Private Const PBM_SETBARCOLOR = (WM_USER + 9)
    ' 1033 is the Decimal value of &H400 + 9, (1024+9)

    Private Const CCM_FIRST = &H2000
    ' 8192 is the Decimal value of &H2000

    Private Const CCM_SETBKCOLOR = (CCM_FIRST + 1)
    ' 8193 is the Decimal value of &H2000 + 1, (8192+1)

    Efi

  5. #5
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195
    Whoa! Thanks a lot, Efi!
    U must have a Visual Basic decompiler inside your brain, eh? WHoa! Cool!
    "Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria

    "I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria

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

Featured