• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

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
0
sidwelle
Asked:
sidwelle
  • 5
  • 5
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now