The new vbAccelerator Site - more VB and .NET Code and Controls

Prevent a window from repainting

Author:

Steve McMahon(steve@vbaccelerator.com)

Keywords:

API,GDI,Graphics,Windows Controls

Updated:

01/08/98

Other Tips
All Tips
By Date
By Subject


API (33)
Bit
Manipulation (3)

Clipboard (3)
Combo
Box (5)

Desktop (3)
GDI (13)
Graphics (13)
Internet (2)
Interprocess
Comms (3)

Keyboard (2)
Mouse (1)
Shell (1)
Sprites (1)
Subclassing (3)
Text
Box (2)

Windows (11)
Windows
Controls (10)



Submit


This tip show show to prevent an area of a window from repainting. When you have a lot of items to add to a control, such as a ListBox or ListView, this can considerably speed up the process. On my system, it speeds up adding 10,000 items to a List Box by over 30%.

Create a new project, and add a ListBox, a Command Button and a CheckBox to the form. Change the caption of the CheckBox to '&Lock Update' and change the caption of the Command Button to '&Load...'. Then paste the following code into the form:

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Private Sub Command1_Click()
Dim i As Long
Dim lTIme As Long

    lTIme = timeGetTime()
   
    If (Check1.Value = Checked) Then
        LockWindowUpdate List1.hWnd
    End If
   
    List1.Clear
    For i = 1 To 10000
        List1.AddItem "Test " & i
    Next i
   
    If (Check1.Value = Checked) Then
        LockWindowUpdate 0
        List1.Refresh
    End If
   
    MsgBox "Time: " & timeGetTime - lTIme
   
End Sub

When you click on the command button, the code will add 10,000 items to the List Box. If the Lock Update check box is checked, windows will prevent any redrawing of the List Box whilst the items are added.


 

Related Tips and Articles:

 
 

About  Contribute  Send Feedback  Privacy

Copyright © 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 01/08/98

g="0" cellspacing="0" width="100%">  

About  Contribute  Send Feedback  Privacy

Copyright © 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 01/08/98