I have the following code at the top of a loop:
For MsgNumber = 1 To Messages 'Loop through all mail
FF_StatusBar_SetText (HWND_FMGMAIL_STATUSBAR, 1, " Downloading Header" + Str$(MsgNumber) + " of" + Str$(Messages) + " ")
FF_DoEvents
FF_ProgressBar_SetPosition(HWND_FMGMAIL_PROGRESSBAR1, MsgNumber / Messages * 100)
The Progressbar flickers and sometimes disappears altogether.
If the code for the Progressbar is placed elsewhere it often barely shows at all.
Removal of the line containing the Statusbar print cures this.
Placing more FF_Doevents or putting it in different positions doesn't help.
Any ideas?
Cheers
Dave
I used the same code as you and I never saw any redraw problems (other than the statusbar text updating way too much).
Try updating the statusbar after so many headers are read. For example, after every 10 headers:
Local MsgNumber As Long
Local Messages As Long
Messages = 10000
For MsgNumber = 1 To Messages 'Loop through all mail
If MsgNumber Mod 10 = 0 Then ' update every 10 messages
FF_StatusBar_SetText (HWND_FORM1_STATUSBAR, 0, " Downloading Header" + Str$(MsgNumber) + " of" + Str$(Messages) + " ")
End If
FF_ProgressBar_SetPosition(HWND_FORM1_PROGRESSBAR1, MsgNumber / Messages * 100)
FF_DoEvents
Next
Maybe it could also be a WinXP Themes thing? Don't know, I test using Win2K.
I just skimmed through everything, but from what I saw you were missing one major thing:
Say your # of messages is an even 100, then the progressbar is the same as the percent, so is updated at each %. If you have say 200 messages then it is different than percent, so it is updating the progressbar twice for every percent and so on. The biggest rule in painting windows is only paint what is needed when it is needed. Calculate the percent, then compare it to the current position. If different then SetPosition.
DoEvents is also a good start. It can still repaint pretty fast though and may vanish as you seen with the other method, so usually I put in an UpdateWindow or some other Redraw method to be sure it draws before going on and it adds that needed delay before going on.
Also, where is the progressbar at? You said removing the StatusBar SetText helped...so, is the bar in the Statusbar? If so, did you SetParent to make sure it was a child of the Statusbar and painted correctly?
I have brought it pretty much under control due to careful positioning of FF_DoEvents statements.
Hopefully the maximum number of messages will not be so high that I need to do any calculations s described above!
QuoteAlso, where is the progressbar at? You said removing the StatusBar SetText helped...so, is the bar in the Statusbar? If so, did you SetParent to make sure it was a child of the Statusbar and painted correctly?
Yes, the PB is indeed positioned on the SB. How do I go about doing the SetParent bit?
Thanks
Dave[/code]
WM_CREATE:
SetParent(HWND_PROGRESS, HWND_STATUSBAR)
Then in WM_SIZE if Size changes effect the Area it is or just in WM_CREATE with code above:
Local updRect As Rect
FF_StatusBar_GetRect(HWND_STATUSBAR, 3, updRect)
MoveWindow(HWND_PROGRESS, updRect.nLeft, updRect.nTop, updRect.nRight-updRect.nLeft, updRect.nBottom-updRect.nTop, %TRUE)
progress= Fix((Current POS, add 1 if 0 based) / Total * 100)
If progress <> OldProg Then ' Update only if new value
FF_ProgressBar_SetPosition(HWND_PROGRESS, progress)
tmpString= Format$(progress) + "%"
SendMessage(HWND_STATUSBAR, %SB_SETTEXT, 4, VarPtr(tmpString))
OldProg= progress
End If
Thanks Roger!
You are welcome, also note that the example above is a multi panel StatusBar and you'd have to adjust the Panel numbers to match how many you have. I think there should be no problem getting it in a single panel/simple one too, but you wouldn't have any text unless you custom draw a progressbar with text, etc.