VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Lock controls for fast updates

Craig Atkins  (1 Submission)   Miscellaneous   Visual Basic 3.0   Beginner   Wed 3rd February 2021

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.

Returns
Nothing

API Declarations
Option Explicit
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) _
As Long
'-- End --'

Rate Lock controls for fast updates (3(3 Vote))
Lock controls for fast updates.bas

Lock controls for fast updates Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters