Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Re: Repainting Question


Message #1 by "Matt Morgan" <mattmorgan@p...> on Mon, 9 Dec 2002 20:58:21
Stuart -

This has greatly helped. I'm making the calls in the forms 
activate/deactivate event handlers. Is there a better place?

Thanks
Matt

> 'Freezing made easy...
'Copyright (C) 2001 by Benjamin Wilger
'E-Mail: Benjamin@A...

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As 
Any) As Long
Private Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, 
lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As 
Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, 
lpRect As RECT) As Long
Private Const WM_SETREDRAW = &HB
Private Const RDW_INVALIDATE = &H1
Private Const RDW_INTERNALPAINT = &H2
Private Const RDW_UPDATENOW = &H100
Private Const RDW_ALLCHILDREN = &H80
Private Type RECT
     Left As Long
     Top As Long
     Right As Long
     Bottom As Long

End Type

'API's Value of True is 1, VB's Value is -1.
Private Const API_TRUE = 1

'For locking any update on a window just use this syntax:
'   SetRedraw Command1.hWnd, True
'if you would like to enable refreshing:
'   SetRedraw Command1.hWnd, False
'THATS IT!
Public Function SetRedraw(hwnd As Long, LockUpdate As Boolean)
     Dim r As RECT

     If LockUpdate = True Then
         SendMessage hwnd, WM_SETREDRAW, 0&, 0&
     Else
         SendMessage hwnd, WM_SETREDRAW, 1, 0&

         GetClientRect hwnd, r
         If RedrawWindow(hwnd, r, 0&, RDW_INVALIDATE Or RDW_INTERNALPAINT 
Or RDW_UPDATENOW Or RDW_ALLCHILDREN) = 0 Then
             Debug.Print "Failure with RedrawWindow!"
         End If

     End If

End Function

At 21:54 23/10/2002, you wrote:
>All,
>
>I have a form with many controls on it. When I call the show method, the
>form is slow to paint; basically, you can almost watch the controls being
>drawn.
>
>Maybe not quite that slow, but I'd rather have a delay, and then an
>instantaneous paint of the whole form.
>
>Any tips?
>
>Thanks
>Matt
>
>---
>Visual C# - A Guide for VB6 Developers
>This book will make it easy to transfer your skills
>from Visual Basic 6 to C#, the language of choice
>of the .NET Framework.
>http://www.wrox.com/ACON11.asp?ISBN=1861007175&p2p0059
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or
>to unsubscribe send a blank email to 


  Return to Index