# CopyRect Function

`Declare Function CopyRect Lib "user32.dll" (lpDestRect As RECT, lpSourceRect As RECT) As Long`

CopyRect sets one rectangle equal to another. This is done by duplicating all of the source rectangle's member values to the corresponding ones in the target rectangle. This is faster than setting all four values manually in your code. The function returns 0 if an error occured, or a non-zero value if successful.

lpDestRect
  The target rectangle to set.
lpSourceRect
  The source rectangle.

Example:

    Dim target As RECT, source As RECT
    ' Set rectangle target equal to rectangle source
    x = GetWindowRect(Form1.hWnd, source)  ' set source to Form1's rectangle
    x = CopyRect(target, source)  ' now both rectangles are equal

Related Call: EqualRect
Category: Rectangles
Back to the index.