Function Reference


_WinAPI_RedrawWindow

Updates the specified rectangle or region in a window's client area

#include <WinAPIGdi.au3>
_WinAPI_RedrawWindow ( $hWnd [, $tRECT = 0 [, $hRegion = 0 [, $iFlags = 5]]] )

Parameters

$hWnd Handle to a Window
$tRECT [optional] $tagRECT structure containing the coordinates of the update rectangle. This parameter is
ignored if the $hRegion parameter identifies a region.
$hRegion [optional] Identifies the update region. If the $hRegion and $tRECT parameters are 0, the entire client
area is added to the update region.
$iFlags [optional] Specifies the redraw flags. This parameter can be a combination of flags that invalidate or validate a window, control repainting, and control which windows are affected:
    $RDW_ERASE - Causes the window to receive a WM_ERASEBKGND message when the window is repainted
    $RDW_FRAME - Causes any part of the nonclient area of the window that intersects the update region to receive a WM_NCPAINT message.
    $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 $tRECT or $hRegion. If both are 0, the entire window is invalidated.
    $RDW_NOERASE - Suppresses any pending $WM_ERASEBKGND messages
    $RDW_NOFRAME - Suppresses any pending $WM_NCPAINT messages
    $RDW_NOINTERNALPAINT - Suppresses any pending internal $WM_PAINT messages
    $RDW_VALIDATE - Validates $tRECT or $hRegion
    $RDW_ERASENOW - Causes the affected windows to receive $WM_NCPAINT and $WM_ERASEBKGND messages, if necessary, before the function returns
    $RDW_UPDATENOW - Causes the affected windows to receive $WM_NCPAINT, $WM_ERASEBKGND, and $WM_PAINT messages, if necessary, before the function returns.
    $RDW_ALLCHILDREN - Includes child windows in the repainting operation
    $RDW_NOCHILDREN - Excludes child windows from the repainting operation

Return Value

Success: True
Failure: False

Remarks

When RedrawWindow is used to invalidate part of the desktop window, the desktop window does not receive a $WM_PAINT message.
To repaint the desktop an application uses the $RDW_ERASE flag to generate a $WM_ERASEBKGND message.

Above constants require #include <WindowsConstants.au3>

Related

$tagRECT

See Also

Search RedrawWindow in MSDN Library.

Example

#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

If Not @Compiled Then Exit MsgBox($MB_ICONWARNING, "_WinAPI_CreatePen Example Script", _
                "When run from SciTE the script won't work properly because SciTE refreshes the screen. Hence the cross does not get fully drawn and disappears in a split second!" & _
                @CRLF & @CRLF & "Please compile the script and run the Exe.")

ShowCross(@DesktopWidth / 2, @DesktopHeight / 2, 20, 2, 0xFF, 3000)

Func ShowCross($iStart_x, $iStart_y, $iLength, $iWidth, $iColor, $iTime)
        Local $hDC, $hPen, $o_Orig

        $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
        $hPen = _WinAPI_CreatePen($PS_SOLID, $iWidth, $iColor)
        $o_Orig = _WinAPI_SelectObject($hDC, $hPen)

        _WinAPI_DrawLine($hDC, $iStart_x - $iLength, $iStart_y, $iStart_x - 5, $iStart_y) ; horizontal left
        _WinAPI_DrawLine($hDC, $iStart_x + $iLength, $iStart_y, $iStart_x + 5, $iStart_y) ; horizontal right
        _WinAPI_DrawLine($hDC, $iStart_x, $iStart_y - $iLength, $iStart_x, $iStart_y - 5) ; vertical up
        ;       _WinAPI_DrawLine($hDC, $iStart_x, $iStart_y + $iLength, $iStart_x, $iStart_y + 5) ; vertical down
        _WinAPI_MoveTo($hDC, $iStart_x, $iStart_y + $iLength)
        _WinAPI_LineTo($hDC, $iStart_x, $iStart_y + 5)

        Sleep($iTime) ; show cross over screen for defined seconds

        ; refresh desktop (clear cross)
        _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)

        ; clear resources
        _WinAPI_SelectObject($hDC, $o_Orig)
        _WinAPI_DeleteObject($hPen)
        _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>ShowCross