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
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 08:28 PM.
Insomnia is just a byproduct of, "It can't be done"
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.
Last edited by LaVolpe; Feb 28th, 2011 at 01:46 PM.
Insomnia is just a byproduct of, "It can't be done"
..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 02:08 PM.
Insomnia is just a byproduct of, "It can't be done"
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