lockwindowupdate

I have a picturebox on a form and the Pctbox contains an array of a user defined control with a count of about 100.  The application updates the Control array every minute and when the form is not minimized the update takes about 8 - 10 seconds.  If the form is minimized, the update takes about 1.9 seconds.

I added 'LockWindowUpdate form.hwnd '  just before the update begins and unlocked it last line in the routine.  But, it only removed about 1 -2 seconds.  I expected it to be the same as if it were minimized.
Do I need to call 'LockWindowUpdate ...' for each control in the array ?
What else can I do to get the time down ?


Thanks
sidwelleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Heathcliff74Commented:
Use this code instead (paste it in a module):

Private Const WM_SETREDRAW = &HB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Public Function StopRedraw(ctrl As Object) As Boolean
    On Error Resume Next
    Dim hdc As Long
    If Not ctrl Is Nothing Then
        StopRedraw = (SendMessage(ctrl.hwnd, WM_SETREDRAW, False, 0&) = 0)
        DoEvents
        If StopRedraw Then
            hdc = GetDC(ctrl.hwnd)
            SendMessage ctrl.hwnd, 15, GetDC(ctrl.hwnd), 0 ' WM_PAINT
            ReleaseDC ctrl.hwnd, hdc
        End If
        DoEvents
    End If
End Function

Public Function StartRedraw(ctrl As Object) As Boolean
    On Error Resume Next
    Dim hdc As Long
    If Not ctrl Is Nothing Then
        StartRedraw = (SendMessage(ctrl.hwnd, WM_SETREDRAW, True, 0&) = 0)
        DoEvents
        If StartRedraw Then
            hdc = GetDC(ctrl.hwnd)
            SendMessage ctrl.hwnd, 15, GetDC(ctrl.hwnd), 0 ' WM_PAINT
            ReleaseDC ctrl.hwnd, hdc
        End If
        DoEvents
    End If
End Function

Use StopRedraw at the beginning and StartRedraw at the end.
0
Heathcliff74Commented:
You probably need to call the functions only once for the entire control. I don't think you need to do it for every picturebox. It the functions give unexpected behaviour I suggest you remove the "DoEvents" in the functions I provided.
0
sidwelleAuthor Commented:
Heathcliff74,  followed your instructions and testing it now.
First time is caused the IDE to hang, not repaint, and then GPF.
Second attempts seems to be behaving. I will let it run for a few days and post back.
Note: You stall have to cause the child Ctrl(s) refresh, repaint in some manner and the StartRedraw.
 
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Heathcliff74Commented:
StartRedraw should cause the DeviceContext to refresh. If it doesn't refresh the child-controls, then you might have to call StartRedraw for all the child-controls. Hope that works for you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sidwelleAuthor Commented:
Heathcliff74,  Tue before TG Day I put the current version of the application that I have in our test system into live, and that will free up the test system.  When I get back from vacation I will add in the code that you posted and I will follow up with results.

Thanks, sorry for the long wait ...
0
sidwelleAuthor Commented:
Heathcliff74, I added your code to the working test system, but I don't see an improvement in the amount of time to update the array.   Do I need to loop through the child controls and stop the redraw on each individually ?

0
Heathcliff74Commented:
I'm not 100% sure how this behaves with nested controls. We use the code a lot when we fill large listviews. The performance inprovement is very high. But I can imagine every control (nested or not) has its own internal "Redraw" property. So I think it is very well possible that you have to set it the "Redraw" property for every nested control to (and set it back at the end). Looping through 100 items takes less than a millisecond, so that should not be a problem. I suggest you try setting the "Redraw" property for every control. Big chance that will improve your performance.
0
sidwelleAuthor Commented:
Looping through the controls did not help, it just used up another 30ms.
0
sidwelleAuthor Commented:
Thanks for the help, I think that slowdown is in the interface between the interface between the vb form module and the ActiveX control module.  Other than that, you are correct I can loop through 100 members of an array in a few milliseconds.  I have plans to rewrite the app using Treeview. I may include your subs in it as well.

Thanks
0
Heathcliff74Commented:
Ok. glad I could help. Good luck with the rest.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.