Sign in to follow this  
Followers 0
Uriziel01

Help in GDI+

6 posts in this topic

#1 ·  Posted (edited)

Hi ! Im having problems with functions from Gdiplus.dll . Im trying to run GdipFillPolygon (or GdipFillPolygonI or GdipFillPolygon2 etc.) but im lost, MSDN says:

GdipFillPolygon(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)

And Im having problems with GDIPCONST GpPointF *points, I dont now how param type use for this and how to send my points array to this functions.

My attempt:

But it is still not working :P

Please help me if you can (I will be very happy even from small help and tips for this !)

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

    Local $hGUI, $hWnd, $hGraphic, $aPoints[6][2],$aPoints2[6][2],$aPoints3[6][2],$hBrush1

; Create GUI
    $hGUI = GUICreate("GDI+", 400, 400)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()

; Draw a polygon
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)

    $aPoints[0][0] = 4
    $aPoints[1][0] = 200
    $aPoints[1][1] = 100
    $aPoints[2][0] = 300
    $aPoints[2][1] = 150
    $aPoints[3][0] = 200
    $aPoints[3][1] = 200
    $aPoints[4][0] = 100
    $aPoints[4][1] = 150
    $hBrush1 = _GDIPlus_BrushCreateSolid ()
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints)
DllCall("gdiplus.dll","ptr","GdipFillPolygon2","ptr",$hGraphic,"ptr",$hBrush1,"int",$aPoints,"int",3)
;;; DllCall("gdiplus.dll","ptr","GdipFillPolygon","ptr",$hGraphic,"ptr",$hBrush1,"str",$aPoints[1][0]&$aPoints[1][0]&$aPoints[2][0]&$aPoints[2][1]&$aPoints[3][0]&$aPoints[3][1],"int",3)
;;;MsgBox(0,"",@error)
    $aPoints2[0][0] = 4
    $aPoints2[1][0] = 100
    $aPoints2[1][1] = 150
    $aPoints2[2][0] = 200
    $aPoints2[2][1] = 200
    $aPoints2[3][0] = 200
    $aPoints2[3][1] = 300
    $aPoints2[4][0] = 100
    $aPoints2[4][1] = 250
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints2)
    $aPoints3[0][0] = 4
    $aPoints3[1][0] = 200
    $aPoints3[1][1] = 200
    $aPoints3[2][0] = 300
    $aPoints3[2][1] = 150
    $aPoints3[3][0] = 300
    $aPoints3[3][1] = 250
    $aPoints3[4][0] = 200
    $aPoints3[4][1] = 300
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints3)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
Edited by Uriziel01

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is older similar example from forum.

Just look at principles ...

#include <GUIConstants.au3>

$GUI = GUICreate("test",300,300,-1,-1,$WS_POPUP)
GUISetBkColor(0xFFFFFF)

; CreatePolyRgn takes an array of points...
; the following goes from
;      0,0 to
;      600,500 to
;      500,800 to
;      100,500 to
;      0,0

$a = CreatePolyRgn("0,0,600,500,500,800,100,500,0,0")
SetWindowRgn($GUI,$a)

$Eggzit = GUICtrlCreateButton("Bye",80,170,60,25)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Eggzit Or $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc

Func CreatePolyRgn($pt)
    Local $ALTERNATE = 1
    Local $buffer = ""

    $pt = StringSplit($pt,",")
    For $i = 1 to $pt[0]
        $buffer = $buffer & "int;"
    Next
    $buffer = StringTrimRight($buffer,1)
    $lppt = DllStructCreate($buffer)
    For $i = 1 to $pt[0]
        DllStructSetData($lppt,$i,$pt[$i])
    Next
    $ret = DllCall("gdi32.dll","long","CreatePolygonRgn", _
            "ptr",DllStructGetPtr($lppt),"int",Int($pt[0] / 2), _
            "int",$ALTERNATE)
    $lppt = 0
    Return $ret[0]
EndFunc
Edited by Zedna
1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You meaby will laught from me but I still cant run this function :\ Can you help me a liitle bit more?

Ok I have founded my misteake (forgothed to write filling type as the last parametr :P )

This is the ready function (if someone will try to do this in future :P ):

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)
    Local $hGUI, $hWnd, $hGraphic, $aPoints[6][2],$aPoints2[6][2],$aPoints3[6][2],$hBrush1,$lppt,$pt[99],$buffer
    $hGUI = GUICreate("GDI+", 400, 400)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)

    $aPoints[0][0] = 4
    $aPoints[1][0] = 200
    $aPoints[1][1] = 100
    $aPoints[2][0] = 300
    $aPoints[2][1] = 150
    $aPoints[3][0] = 200
    $aPoints[3][1] = 200
    $aPoints[4][0] = 100
    $aPoints[4][1] = 150
    $hBrush1 = _GDIPlus_BrushCreateSolid ()
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints)
    Local $punkty[10]
    $punkty[0]=8
    $punkty[1]=200
    $punkty[2]=100
    $punkty[3]=300
        $punkty[4]=150
            $punkty[5]=200
                $punkty[6]=200
                    $punkty[7]=100
                        $punkty[8]=150
    for $i=1 to 8
        $buffer=$buffer&"int;"
    Next
                   $buffer = StringTrimRight($buffer,1)
    $lppt = DllStructCreate($buffer)
    For $i = 1 to 8
        DllStructSetData($lppt,$i,$punkty[$i])
    Next
DllCall("gdiplus.dll","long","GdipFillPolygonI","ptr",$hGraphic,"ptr",$hBrush1,"ptr",DllStructGetPtr($lppt),"int",Int($punkty[0] / 2),"int",1)
    $aPoints2[0][0] = 4
    $aPoints2[1][0] = 100
    $aPoints2[1][1] = 150
    $aPoints2[2][0] = 200
    $aPoints2[2][1] = 200
    $aPoints2[3][0] = 200
    $aPoints2[3][1] = 300
    $aPoints2[4][0] = 100
    $aPoints2[4][1] = 250
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints2)
    $aPoints3[0][0] = 4
    $aPoints3[1][0] = 200
    $aPoints3[1][1] = 200
    $aPoints3[2][0] = 300
    $aPoints3[2][1] = 150
    $aPoints3[3][0] = 300
    $aPoints3[3][1] = 250
    $aPoints3[4][0] = 200
    $aPoints3[4][1] = 300
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints3)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
Edited by Uriziel01

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

_GDIPlus_GraphicsFillPolygon() was added to GDIPlus udf since Autoit Beta 3.2.13.0

(I submitted it :P )

; #FUNCTION# ===================================================================================
; Name...........: _GDIPlus_GraphicsFillPolygon
; Description ...: Fill a polygon
; Syntax.........: _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints[, $hBrush = 0])
; Parameters ....: $hGraphics   - Handle to a Graphics object
;                  $aPoints     - Array that specify the vertices of the polygon:
;                  |[0][0] - Number of vertices
;                  |[1][0] - Vertice 1 X position
;                  |[1][1] - Vertice 1 Y position
;                  |[2][0] - Vertice 2 X position
;                  |[2][1] - Vertice 2 Y position
;                  |[n][0] - Vertice n X position
;                  |[n][1] - Vertice n Y position
;                  $hBrush      - Handle to a brush object that is used to fill the polygon.
;                               - If $hBrush is 0, a solid black brush is used.
; Return values .: Success      - True
;                  Failure      - False
; Author ........:
; Modified.......: smashly
; Remarks .......:
; Related .......:
; Link ..........; @@MsdnLink@@ GdipFillPolygonI
; Example .......; Yes
; ===============================================================================================
Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError

    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next

    _GDIPlus_BrushDefCreate($hBrush)
    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "hWnd", $hGraphics, "hWnd", $hBrush, _
            "ptr", $pPoints, "int", $iCount, "int", "FillModeAlternate")
    $tmpError = @error
    $tmpExError = @extended
    _GDIPlus_BrushDefDispose()
    If $tmpError Then Return SetError($tmpError, $tmpExError, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_GraphicsFillPolygon

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Heee? I have 3.2.13.3 and I dont have it. really :P

Edited by Uriziel01

Share this post


Link to post
Share on other sites

Heee? I have 3.2.13.3 and I dont have it. really :P

That's odd.. the function I posted before was copied from the GDIPlus.au3 out of my Autoit Beta v3.2.13.3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0