Marquee Progressbar-VBForums
Results 1 to 11 of 11

Thread: Marquee Progressbar

  1. #1

    Thread Starter
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Marquee Progressbar

    Makes a progress bar marquee. Only works with XP styles turned on


    Code:
    Private Const WM_USER = &H400
    Private Const PBM_SETMARQUEE = WM_USER + 10
    Private Const GWL_STYLE = (-16)
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
    Dim PrevStyle As Long
    Private Function SetUpMarquee(ObjProgressBar As ProgressBar, Optional TurnOn As Boolean, Optional Speed As Integer = 50)
    Select Case TurnOn
        Case True
            'Set the style to Marquee
            SetWindowLong ObjProgressBar.hwnd, GWL_STYLE, PrevStyle Or PBM_SETMARQUEE
            'Make it automatically scroll
            SetUpMarquee = SendMessage(ObjProgressBar.hwnd, PBM_SETMARQUEE, CLng(TurnOn), CLng(Speed))
        Case False
            'Set the Style Back
            SetWindowLong ObjProgressBar.hwnd, GWL_STYLE, PrevStyle
    End Select
    End Function
    
    Private Sub Form_Load()
        'Get the current Style
        PrevStyle = GetWindowLong(ProgressBar1.hwnd, GWL_STYLE)
        
        'Turn it on or off and speed
        SetUpMarquee ProgressBar1, True, 50
        ProgressBar1.Value = 50         'Just to show that when its on, setting the value will not work
    End Sub


    References:
    • The need to set the style to Marquee from Link
    • Making it Automatic, research on MSDN and experimenting

  2. #2
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

    Re: Marquee Progressbar

    Hello, please help. i tried to use your code, and my progressbar is no longer displaying
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  3. #3
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Marquee Progressbar

    What verson of the common conrols are you using? Try v5 not v6.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

    Re: Marquee Progressbar

    yes am using version 5 sp2. and notic this. whe i turn off the maquree thing and recompile, my progressbar appears
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  5. #5
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Marquee Progressbar

    Are you using a manifest file and is the application compiled? Appears to be a requirement. I quickly tested the code in that scenario & it worked flawlessly in XP. Didn't test in Vista & also didn't test what would happen if value was the progressbar.Min value, might want to do that & ensure it is > .Min

    Edited: Another idea. Where is your common control initialization happening? May want to make it happen in Sub Main, not form_load.
    Describe your progressbar properties and what O/S you are using. Maybe we can replicate the problem?

    Edited Again: After looking closer at the code above. This line is in error I believe
    Code:
    SetWindowLong ObjProgressBar.hwnd, GWL_STYLE, PrevStyle Or PBM_SETMARQUEE
    Using PBM_SETMARQUEE includes the PBS_MARQUEE bit, but also includes a ton more that probably should not be included. The correct call should be as follows.
    Code:
    Const PBS_MARQUEE As Long = &H8
    SetWindowLong ObjProgressBar.hwnd, GWL_STYLE, PrevStyle Or PBS_MARQUEE
    Last edited by LaVolpe; Feb 26th, 2011 at 07:28 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Marquee Progressbar

    FYI: To have a marquee progressbar without including v5 of the common controls (or any version really), you can use the attached class. Note that common controls v6 must be installed on the user's system, but does not have to be referenced in your project.
    As noted above, themed controls needed to have a marquee style

    - Copy attached txt file contents to a new class within your project
    - Declare cPBar As cProgressbar in your declarations section
    - Set cPBar = New cProgressbar before using & call its CreateProgressBar function at some point

    Provided as-is. Should be usable & read comments regarding calls that are for Vista+ only.

    Advantages:
    - Min/Max values can be Long vs. restricted to Integer
    - Uses v6 progress bar vs. v5 & no common controls need to be referenced in the project
    - Built-in added features like back/fore color (unthemed), marquee pausing (Vista+), marquee speed adjustments & a few more
    Disadvantages:
    - No WYSIWYG during design time. May want to use a non-visible shape control on the form to represent the space to be used by the progress bar during runtime
    - No TabStop, Container & other typical VB properties; though most can be added to the class, not all
    - No tooltip without adding more API calls


    Edited: When creating the progress bar, the position and dimensions passed must be in pixels, not twips or anything else.
    I also did not dummy-proof the class. Don't attempt to pass invalid values & never pass ContainerHwnd as zero when creating the progressbar. Always use Me.hWnd, Picture1.hWnd, Frame1.hWnd, etc.

    If the OP of this thread wishes this project removed, I'll do so. Didn't want to compete; just wanted to throw another option out there. If one is already referencing/using v5 of the common controls library; don't use this method, use the method in post #1 & look also at my post #5.
    Attached Files Attached Files
    Last edited by LaVolpe; Feb 28th, 2011 at 12:46 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

    Re: Marquee Progressbar

    Quote Originally Posted by LaVolpe View Post
    Edited: Another idea. Where is your common control initialization happening? May want to make it happen in Sub Main, not form_load.
    sub main()
    Quote Originally Posted by LaVolpe View Post
    Describe your progressbar properties
    common controls v5sp2
    Quote Originally Posted by LaVolpe View Post
    what O/S you are using. Maybe we can replicate the problem?
    WinXpsp3

    I noticed i made and error, i did not include this line before, so i included it.
    Code:
    PrevStyle = GetWindowLong(pbrMain.hwnd, GWL_STYLE)
    The ProgressBar is now showing, but not scrolling!!
    if i minimize the form and open it quickly, the green bars appears to move one step each time

    What now!

    i subclassed my toolbar to make the background gradient, could this be interfering with it
    Last edited by coolcurrent4u; Feb 27th, 2011 at 02:42 AM.
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  8. #8
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Marquee Progressbar

    Quote Originally Posted by coolcurrent4u View Post
    ..i subclassed my toolbar to make the background gradient, could this be interfering with it
    Maybe. When controls are themed; the O/S kinda takes responsibility for drawing them. When you interfere, unexpected results. Simply don't subclass and see if it works. If so, your subclassing is the reason. Also look at my edited reply in post #5 and see if that could be contributing.

    Note: The marquee style is simple really. It draws a fixed bitmap at different X coordinates within the progress bar DC, using a timer. However, to replicate that manually, a timer still required, but you'd have to subclass and draw that fixed portion manually via the WM_Paint event. Subclassing needed because no setting on the progress bar allows you to say I want a value of n offset by x pixels. The progress always begins drawing at the left or bottom, depending on horizontal/vertical orientation.
    Last edited by LaVolpe; Feb 27th, 2011 at 01:08 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

    Re: Marquee Progressbar

    Hello, i removed the subclassing, and it still did not work.
    How do i trouble shoot this one now, but doing the marquee thing on a different new project seems to work fine. Could a timer be interfering with it, i have a timer control on my form too
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  10. #10
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: Marquee Progressbar

    A timer won't be interfering. I would look carefully at your code. You admitted you left something out earlier; maybe you have another mistake too?
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,012

    Re: Marquee Progressbar

    Here is another example that you can test. It also demonstrates some other standard "states" supported by the Common Controls 6.0 ProgressBar.

    Open the project, compile, and run the compiled program to test it.
    Attached Images Attached Images  
    Attached Files Attached Files

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.