VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Lock controls for fast updates

by Craig Atkins (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

When you, for example, add listitems to a listbox or combo box Windows repaints the box after each addidtion. This takes up processing time, makes your app look bad (due to flickering) and if you add a lot of items it can take a long time(Especially if the Combo or Listbox Sorted properety is set to true) Windows provides an API called LockWindowUpdate that you can use to keep Windows from updating a control with a hWnd property. This code is a simple way to call that function.

Inputs
objX As Object (The object to lock, i.e combo1) cLock As Boolean (True locks the object, False unlocks it)
Assumes
To use the sub use something like: LockControl Combo1, True ..which will prevent the control called Combo1 from repainting hence loading about 30% faster in a non sorted Combo box when adding 10.000 items. To make the control update again use this code: LockControl Combo1, False ...which makes Windows update the control Combo1 once again.
Code Returns
Nothing
API Declarations
Option Explicit
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) _
As Long
'-- End --'

Rate Lock controls for fast updates

Public Sub LockControl(objX As Object, cLock As Boolean)
 Dim i As Long
 If cLock Then
  ' This will lock the control
  LockWindowUpdate objX.hWnd
 Else
  ' This will unlock controls
  LockWindowUpdate 0
  objX.Refresh
 End If
End sub
'-- End --'

Download this snippet    Add to My Saved Code

Lock controls for fast updates Comments

No comments have been posted about Lock controls for fast updates. Why not be the first to post a comment about Lock controls for fast updates.

Post your comment

Subject:
Message:
0/1000 characters