# CodeGuru Technical FAQs > CodeGuru Individual Visual Basic FAQs >  RedrawWindow

## TT(n)

RedrawWindow redraws all or part of a window according to the fuRedraw flag.


```
    Const RDW_INVALIDATE As Int32 = 1 'Invalidates the redraw area.
    Const RDW_INTERNALPAINT As Int32 = 2 'A WM_PAINT message is posted to the window even if it is not invalid.
    Const RDW_ERASE As Int32 = 4 '	The background of the redraw area is erased before drawing. RDW_INVALIDATE must also be specified.
    Const RDW_VALIDATE As Int32 = 8 'Validates the redraw area.
    Const RDW_NOINTERNALPAINT As Int32 = 16 'Prevents any pending WM_PAINT messages that were generated internally or by this function. WM_PAINT messages will still be generated for invalid areas.
    Const RDW_NOERASE As Int32 = 32 'Prevents the background of the redraw area from being erased.
    Const RDW_NOCHILDREN As Int32 = 64 'Redraw operation excludes child windows if present in the redraw area.
    Const RDW_ALLCHILDREN As Int32 = 128 'Redraw operation includes child windows if present in the redraw area.
    Const RDW_UPDATENOW As Int32 = 256 'Updates the specified redraw area immediately.
    Const RDW_ERASENOW As Int32 = 512 'Erases the specified redraw area immediately.
    Const RDW_FRAME As Int32 = 1024 'Updates the nonclient area if included in the redraw area. RDW_INVALIDATE must also be specified.
    Const RDW_NOFRAME As Int32 = 2048 'Prevents the nonclient area from being redrawn if it is part of the redraw area. RDW_VALIDATE must also be specified.
    Const HWND_DESKTOP As Int32 = 0
    Private Structure RECT
        Public rLeft, rTop, rRight, rBottom As Int32
    End Structure
    Private Declare Function apiRedrawWindow Lib "user32" Alias "RedrawWindow" (ByVal hWnd As Int32, ByVal lprcUpdate As Boolean, ByVal hrgnUpdate As Int32, ByVal fuRedraw As Int32) As Int32

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        apiRedrawWindow(Me.Handle.ToInt32, False, 0, RDW_INVALIDATE) 'Redraw this window (invoke a Paint-event)

        'apiRedrawWindow(HWND_DESKTOP, False, 0, RDW_INVALIDATE) 'Redraw desktop window (invoke a Paint-event)
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Me.Text = (CInt(Me.Text) + 1).ToString
    End Sub


'· hWnd
'Identifies the window to be redrawn. If this parameter is NULL, the desktop window is updated.

'· lprcUpdate
'Points to a RECT structure containing the coordinates of the update rectangle.
' This parameter is ignored if the hrgnUpdate parameter identifies a region.

'· hrgnUpdate
'Identifies the update region. If both the hrgnUpdate and lprcUpdate parameters are NULL,
' the entire client area is added to the update region.

'· flags
'Specifies one or more redraw flags. This parameter can be a combination of flags that invalidate or validate a 
'window, control repainting, and control which windows are affected by RedrawWindow.
'The following flags are used to invalidate the window:

'RDW_ERASE Causes the window to receive a WM_ERASEBKGND message when the window is repainted. 
'The RDW_INVALIDATE flag must also be specified; otherwise, RDW_ERASE has no effect.

'RDW_FRAME Causes any part of the nonclient area of the window that intersects the update region to receive a
'WM_NCPAINT message. The RDW_INVALIDATE flag must also be specified; otherwise, RDW_FRAME has no effect. 
'The WM_NCPAINT message is typically not sent during the execution of RedrawWindow unless either RDW_UPDATENOW or
' RDW_ERASENOW is specified.

'RDW_INTERNALPAINT Causes a WM_PAINT message to be posted to the window regardless of whether any portion of the 
'window is invalid.

'RDW_INVALIDATE Invalidates lprcUpdate or hrgnUpdate (only one may be non-NULL). If both are NULL, the entire
'window is invalidated.

'The following flags are used to validate the window:

'RDW_NOERASE' Suppresses any pending WM_ERASEBKGND messages.

'RDW_NOFRAME' Suppresses any pending WM_NCPAINT messages. This flag must be used with RDW_VALIDATE and is typically
' used with RDW_NOCHILDREN. RDW_NOFRAME should be used with care, as it could cause parts of a window to be painted
' improperly.

'RDW_NOINTERNALPAINT Suppresses any pending internal WM_PAINT messages. This flag does not affect WM_PAINT messages
' resulting from a non-NULL update area.

'RDW_VALIDATE Validates lprcUpdate or hrgnUpdate (only one may be non-NULL). If both are NULL, the entire window is
' validated.' This flag does not affect internal WM_PAINT messages.

'The following flags control when repainting occurs.
'RedrawWindow will not repaint unless one of these flags is specified.

'RDW_ERASENOW Causes the affected windows (as specified by the RDW_ALLCHILDREN and RDW_NOCHILDREN flags) to receive
' WM_NCPAINT and WM_ERASEBKGND messages, if necessary, before the function returns. WM_PAINT messages are received
' at the ordinary time.

'RDW_UPDATENOW Causes the affected windows (as specified by the RDW_ALLCHILDREN and RDW_NOCHILDREN flags) to
' receive WM_NCPAINT, WM_ERASEBKGND, and WM_PAINT messages, if necessary, before the function returns.

'By default, the windows affected by RedrawWindow depend on whether the given window has the WS_CLIPCHILDREN style.
' Child windows that are not the WS_CLIPCHILDREN style are unaffected; non-WS_CLIPCHILDREN windows are recursively
' validated or invalidated until a WS_CLIPCHILDREN window is encountered. 
'The following flags control which windows are affected by the RedrawWindow function:

'RDW_ALLCHILDREN Includes child windows, if any, in the repainting operation.
'RDW_NOCHILDREN Excludes child windows, if any, from the repainting operation.
```

----------

