Function Reference


_WinAPI_GradientFill

Fills rectangle or triangle gradient

#include <WinAPIGdi.au3>
_WinAPI_GradientFill ( $hDC, Const ByRef $aVertex [, $iStart = 0 [, $iEnd = -1 [, $bRotate = False]]] )

Parameters

$hDC Handle to the device context.
$aVertex The 2D array ([x1, y1, $iRGB1], [x2, y2, $iRGB2], ... [xN, yN, $iRGBN]) that contains the necessary
gradient vertices. Each vertex in this array contains the following parameters.
x - The x-coordinate, in logical units.
y - The y-coordinate, in logical units
rgb - The color information at the point of x, y.
$iStart [optional] The index of array to start filling at.
$iEnd [optional] The index of array to stop filling at.
$bRotate [optional] Specifies whether fills a rectangle from left to right edge (horizontal gradient).
    $bRotate used only for the rectangular gradients, for the triangular gradients this parameter will be ignored,
    valid values:
        True - Fills from left to right edge.
        False - Fills from top to bottom edge (Default).

Return Value

Success: 1.
Failure: 0.

Remarks

If the number of vertices defined by using $iStart and $iEnd parameters is 2, _WinAPI_GradientFill() function
fills a rectangle. If the number of vertices is 3, fills a triangle. For the rectangle, the vertices must
specify its upper left and lower right corners. Note that $aVertex array may contain any number of vertices
of the gradient, but only 2 or 3 vertices may be used at the same time from this array.
Otherwise, the function is fails.

_WinAPI_GradientFill() function can only fill the rectangle or triangle at one call. Use multiple calls this
function to fill a complex gradients.

See Also

Search GdiGradientFill in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>

Local $aVertex[6][3] = [[0, 0, 0xFF0000], [400, 400, 0x00FF00], [0, 400, 0x0000FF], [0, 0, 0xFF0000], [400, 0, 0xFFFF00], [400, 400, 0x00FF00]]

; Create GUI
Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)
Local $idPic = GUICtrlCreatePic('', 0, 0, 400, 400)
Local $hPic = GUICtrlGetHandle($idPic)

; Create gradient
Local $hDC = _WinAPI_GetDC($hPic)
Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, 400, 400)
Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
_WinAPI_GradientFill($hDestDC, $aVertex, 0, 2)
_WinAPI_GradientFill($hDestDC, $aVertex, 3, 5)

_WinAPI_ReleaseDC($hPic, $hDC)
_WinAPI_SelectObject($hDestDC, $hDestSv)
_WinAPI_DeleteDC($hDestDC)

; Set gradient to control
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE