This example demonstrates how to force a redraw of an area of a window. Sometimes this is needed, such as when you use the LockWindowUpdate API function to speed up the data loading of a control.
Create a new project and add a module with the following code:
Private Type RECT
Left as Long
Top as Long
Right as Long
Bottom as Long
End Type
Private Type Pointapi
X as Long
Y as Long
End Type
Private Declare Function getwindowrect Lib "user32" (ByVal hWnd as Long, lprect as RECT) as Long
Private Declare Function getclientrect Lib "user32" (ByVal hWnd as Long, lprect as RECT) as Long
Private Declare Function invalidaterect Lib "user32" (ByVal hWnd as Long, lprect as RECT, ByVal berase as long) as long
Private Declare Function screentoclient Lib "user32" (ByVal hWnd as Long, lppoint as POINTAPI) as Long
Public Sub Repaintwindow (ByRef objthis as Object, Optional ByVal bclientareaonly as Boolean = True)
Dim TR as RECT
Dim TP as Pointapi
If (bclientareaonly) Then
GetClientRect Objthis.hwnd, TR
Else
GetWindowRect Objthis.hwnd, TR
tp.x = TR.LEFT:TP.Y = Tr.top
ScreenToClient Objthis.hwnd, TP
Tr.left = Tp.x:tr.top = Tp.y
tp.x = TR.RIGHT:TP.Y = Tr.bottom
ScreenToClient Objthis.hwnd,
TP tr.right = Tp.x:tr.bottom = Tp.y
End If
InvalidateRect Objthis.hwnd, TR, 1
End Sub
Place a button and list box on the form. Make the list box large enough to observe the effect. Then add the following code:
Private Sub Command1_Click ()
Repaintwindow List1
End Sub
Private Sub Form_Load ()
Dim I as Long
For i = 1 to 200
List1.AddItem "TestItem" & I
Next I
End Sub