Disabling display during updates


Programs such as WinWatch that update many list items at one time need some way to quiet down the display so that the list box isn’t redrawn every time an item is added. I know of three ways to do this:
You can experiment with these three solutions by setting different compile-time constants in the RefreshModuleList sub and observing the difference. If you’re willing to take my word for it, the code for the winning entry is on the following page.

#If fComponent Then
Sub SetRedraw(ctl As Object, f As Boolean)
#Else
Sub SetRedraw(ctl As Control, f As Boolean)
#End If
Call SendMessageVal(ctl.hWnd, WM_SETREDRAW, -CLng(f), 0&)
End Sub

Notice how the flag parameter is a Boolean, but the call converts it to a Long and negates it. This is because the WM_SETREDRAW message is extremely picky. It wants a C style TRUE (1) or FALSE (0). Other values, such as a Visual Basic style True (-1), might not work. The Boolean type converts any weird value you might receive (such as 237) to True or False. The CLng conversion converts the True or False to -1 or 0. The negation converts -1 or 0 to 1 or 0. Ugly. Windows should accept zero and nonzero like everybody else.