GradientFillRect

    • Offizieller Beitrag

    Hi,
    ich habe mal probiert folgendes VB-Bsp.:

    Spoiler anzeigen

    nach AutoIt zu portieren. Leider ohne sichtbaren Erfolg. :S Der Dll-Call wird zwar ohne Fehler ausgeführt, aber der Return ist immer '0', also Mißerfolg. Hat jemand eine Idee?

    Spoiler anzeigen
    [autoit]

    Global Const $tagTRIVERTEX = 'long x;long y;int Red;int Green;int Blue;int Alpha'
    Global Const $tagGRADIENT_RECT = 'ulong UpperLeft;ulong LowerRight'
    Global Const $GRADIENT_FILL_RECT_H = 0x0 ;'In this mode, two endpoints describe a rectangle. The rectangle is
    ;~ 'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
    ;~ 'the color from the top to bottom edge and fills the interior.
    Global Const $GRADIENT_FILL_RECT_V = 0x1 ;'In this mode, two endpoints describe a rectangle. The rectangle is
    ;~ ' defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
    ;~ ' the color from the top to bottom edge and fills the interior.
    Global Const $GRADIENT_FILL_TRIANGLE = 0x2 ;'In this mode, an array of TRIVERTEX structures is passed to GDI
    ;~ 'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
    ;~ 'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
    Global Const $GRADIENT_FILL_OP_FLAG = 0xFF

    [/autoit] [autoit][/autoit] [autoit]

    Func GradientFillRect($hdc, $pTRIVERTEX, $dwNumVertex, ByRef $tGRADIENT_RECT, $dwNumMesh, $dwMode)
    Local $ret = DllCall("msimg32", 'long', "GradientFill", 'long', $hdc, 'ptr', $pTRIVERTEX, _
    'long', $dwNumVertex, 'ptr', $tGRADIENT_RECT, 'long', $dwNumMesh, 'long', $dwMode)
    If @error > 0 Then Return SetError(1,@error,-1)
    Return $ret[0] ; True or False
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func LongToUShort($Unsigned)
    Return Int($Unsigned - 0x10000)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Form_Paint()

    [/autoit] [autoit][/autoit] [autoit]

    Func Form_Paint()
    Local $width = 400, $height = 300
    Local $gui = GUICreate('Test', $width, $height)
    Local $vert0 = DllStructCreate($tagTRIVERTEX)
    Local $vert1 = DllStructCreate($tagTRIVERTEX)
    Local $vert = DllStructCreate('ptr[2]')
    DllStructSetData($vert, 1, DllStructGetPtr($vert0), 1)
    DllStructSetData($vert, 1, DllStructGetPtr($vert1), 2)

    [/autoit] [autoit][/autoit] [autoit]

    Local $gRect = DllStructCreate($tagGRADIENT_RECT)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ 'from black
    DllStructSetData($vert0, 'x', 0)
    DllStructSetData($vert0, 'y', 0)
    DllStructSetData($vert0, 'Red', 0)
    DllStructSetData($vert0, 'Green', 0xFF)
    DllStructSetData($vert0, 'Blue', 0)
    DllStructSetData($vert0, 'Alpha', 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ 'to blue
    DllStructSetData($vert1, 'x', $width)
    DllStructSetData($vert1, 'y', $height)
    DllStructSetData($vert1, 'Red', 0)
    DllStructSetData($vert1, 'Green', 0)
    DllStructSetData($vert1, 'Blue', LongToUShort(0xFF00))
    DllStructSetData($vert1, 'Alpha', 0)

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($gRect, 'UpperLeft', 0)
    DllStructSetData($gRect, 'LowerRight', 1)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    Local $ret = GradientFillRect(WinGetHandle($gui), $vert, 2, $gRect, 1, $GRADIENT_FILL_RECT_H)

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite($ret & ' @err: ' & @error & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3
    EndFunc

    [/autoit]
  • z.B. musst du DLLStructGetPtr verwenden _WinAPI_GetDC und das Array ist ein direktes Array und kein Array von Pointern.

    Spoiler anzeigen
    [autoit]

    #include<WinAPI.au3>
    Global Const $tagTRIVERTEX = 'long x;long y;ushort Red;ushort Green;ushort Blue;ushort Alpha'
    Global Const $tagGRADIENT_RECT = 'ulong UpperLeft;ulong LowerRight'
    Global Const $GRADIENT_FILL_RECT_H = 0x0 ;'In this mode, two endpoints describe a rectangle. The rectangle is
    ;~ 'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
    ;~ 'the color from the top to bottom edge and fills the interior.
    Global Const $GRADIENT_FILL_RECT_V = 0x1 ;'In this mode, two endpoints describe a rectangle. The rectangle is
    ;~ ' defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
    ;~ ' the color from the top to bottom edge and fills the interior.
    Global Const $GRADIENT_FILL_TRIANGLE = 0x2 ;'In this mode, an array of TRIVERTEX structures is passed to GDI
    ;~ 'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
    ;~ 'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
    Global Const $GRADIENT_FILL_OP_FLAG = 0xFF

    [/autoit] [autoit][/autoit] [autoit]

    Func GradientFillRect($hdc, $pTRIVERTEX, $dwNumVertex, ByRef $tGRADIENT_RECT, $dwNumMesh, $dwMode)
    Local $ret = DllCall("Msimg32.dll", 'long', "GradientFill", 'handle', $hdc, 'ptr', $pTRIVERTEX, _
    'ulong', $dwNumVertex, 'ptr', $tGRADIENT_RECT, 'ulong', $dwNumMesh, 'ulong', $dwMode)
    If @error Then Return SetError(1,@error,0)
    Return $ret[0] ; True or False
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Form_Paint()

    [/autoit] [autoit][/autoit] [autoit]

    Func Form_Paint()
    Local $width = 400, $height = 300
    Local $gui = GUICreate('Test', $width, $height)
    Local $SIZEOF_TRIVERTEX = DllStructGetSize(DllStructCreate( $tagTRIVERTEX ,1))
    Local $vert = DllStructCreate('byte[' & $SIZEOF_TRIVERTEX*2 & "]")

    Local $vert0 = DllStructCreate($tagTRIVERTEX, DllStructGetPtr($vert))
    Local $vert1 = DllStructCreate($tagTRIVERTEX, DllStructGetPtr($vert)+$SIZEOF_TRIVERTEX)

    [/autoit] [autoit][/autoit] [autoit]

    Local $gRect = DllStructCreate($tagGRADIENT_RECT)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ 'from black
    DllStructSetData($vert0, 'x', 0)
    DllStructSetData($vert0, 'y', 0)
    DllStructSetData($vert0, 'Red', 0)
    DllStructSetData($vert0, 'Green', 0)
    DllStructSetData($vert0, 'Blue', 0)
    DllStructSetData($vert0, 'Alpha', 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ 'to blue
    DllStructSetData($vert1, 'x', $width)
    DllStructSetData($vert1, 'y', $height)
    DllStructSetData($vert1, 'Red', 0)
    DllStructSetData($vert1, 'Green', 0)
    DllStructSetData($vert1, 'Blue', 0xFE00)
    DllStructSetData($vert1, 'Alpha', 0)

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($gRect, 'UpperLeft', 0)
    DllStructSetData($gRect, 'LowerRight', 1)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    $hDC = _WinAPI_GetDC($gui)
    Local $ret = GradientFillRect($hdc, DllStructGetPtr($vert), 2, DllStructGetPtr($gRect), 1, $GRADIENT_FILL_RECT_H)
    _WinAPI_ReleaseDC($gui, $hDC)

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite($ret & ' @err: ' & @error & " @ext: " & @extended & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3
    EndFunc

    [/autoit]