Problem mit Array..übergeben?? Dim, Local??

  • Hallo,

    ich habe ein Fenster das ich, je nach X oder Y Zähler, in Rechtecke aufteilen möchte!

    Wenn ich nun mit der Maus auf ein Rechteck klicke soll es sich entweder schwarz(falls weiss) oder weiss(falls schwarz) färben! Jedoch bekomm ich die zuweisung bzw. übergabe mit dem Array nich hin..kann mich jemand anstubsen??


    Update:
    [
    spoiler]

    [autoit]

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>
    #include <Array.au3>
    Opt("GUICoordMode", 1)
    Opt("MouseCoordMode", 2)
    Opt("PixelCoordMode", 2)
    Local $hDLL = DllOpen("user32.dll")
    $Form1 = GUICreate("Form1", 292, 372, 281, 172)
    $Graphic1 = GUICtrlCreateGraphic(16, 24, 250, 250, BitOR($GUI_SS_DEFAULT_GRAPHIC, $SS_WHITERECT, $SS_SUNKEN))
    $Input1 = GUICtrlCreateInput("", 22, 304, 40, 21, $ES_CENTER, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
    $Input2 = GUICtrlCreateInput("", 72, 304, 40, 21, $ES_CENTER, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
    $UpDwn1 = GUICtrlCreateUpdown($Input1)
    $UpDwn2 = GUICtrlCreateUpdown($Input2)
    $Label1 = GUICtrlCreateLabel("X-Anzahl", 20, 288, 45, 17)
    $Label2 = GUICtrlCreateLabel("Y-Anzahl", 70, 288, 45, 17)
    GUISetState(@SW_SHOW)
    GUICtrlSetFont($Label1, 8, 400, 5)
    GUICtrlSetFont($Label1, 8, 400, 5)
    GUICtrlSetData($Input1, 5)
    GUICtrlSetData($Input2, 5)
    $cX = GUICtrlRead($Input1)
    $cY = GUICtrlRead($Input2)
    $cK = $cX * $cY
    $width = 250
    $height = 250
    Dim $acK[$cK + 1][4]
    $acK[0][0] = 'links oben X,Y'
    $acK[0][1] = 'rechts unten X,Y'
    $acK[0][2] = 'width/height'
    $acK[0][3] = 'black = 1'
    For $i = 1 To $cK
    $acK[$i][2] = 0
    Next

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)

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

    _calc()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _END()
    Case $GUI_EVENT_PRIMARYDOWN
    $pos = MouseGetPos()
    $var = PixelGetColor($pos[0], $pos[1])
    $cK = $cX * $cY
    For $i = 1 To $cK
    $lo = StringSplit($acK[$i][0], ',')
    $ru = StringSplit($acK[$i][1], ',')
    $wh = StringSplit($acK[$i][2], ',')
    If _WinAPI_PtInRectEx($pos[0] - 16, $pos[1] - 24, $lo[1], $lo[2], $ru[1], $ru[2]) = True Then
    If $acK[$i][3] = 0 Then
    $acK[$i][3] = 1
    Else
    $acK[$i][3] = 0
    EndIf
    EndIf
    Next
    _draw()
    EndSwitch
    ;X und Y Anzahl/Kästchen begrenzen
    If GUICtrlRead($Input1) >= 26 Then
    GUICtrlSetData($Input1, 25)
    EndIf
    If GUICtrlRead($Input2) >= 26 Then
    GUICtrlSetData($Input2, 25)
    EndIf
    If GUICtrlRead($Input1) <= 0 Then
    GUICtrlSetData($Input1, 1)
    EndIf
    If GUICtrlRead($Input2) <= 0 Then
    GUICtrlSetData($Input2, 1)
    EndIf
    ;Wenn sich Anzahl Kästchen ändert
    If GUICtrlRead($Input1) <> $cX Or GUICtrlRead($Input2) <> $cY Then
    $cX = GUICtrlRead($Input1)
    $cY = GUICtrlRead($Input2)
    _WinAPI_RedrawWindow($Form1)
    _calc()
    EndIf
    WEnd

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

    Func _calc()
    $wK = $width / $cX
    $hK = $height / $cY
    $cK = $cX * $cY
    Dim $xK[$cX + 1]
    Dim $yK[$cY + 1]
    Dim $acK[$cK + 1][4]
    $acK[0][0] = 'links oben X,Y'
    $acK[0][1] = 'rechts unten X,Y'
    $acK[0][2] = 'width/height'
    $acK[0][3] = 'black = 1'
    $a = 1
    For $i = 1 To $cX
    $xK[$i] = ($i * $wK) - $wK
    For $j = 1 To $cY
    $yK[$j] = ($j * $hK) - $hK
    $acK[$a][0] = $xK[$i] & ',' & $yK[$j]
    $acK[$a][1] = $xK[$i] + $wK & ',' & $yK[$j] + $hK
    $acK[$a][2] = $wK & ',' & $hK
    $acK[$a][3] = 0
    If $a < $cK Then
    $a = $a + 1
    EndIf
    Next
    Next
    _draw()
    EndFunc ;==>_calc
    Func _draw()
    _WinAPI_RedrawWindow($Form1)
    For $i = 1 To $cK
    $lo = StringSplit($acK[$i][0], ',')
    $wh = StringSplit($acK[$i][2], ',')
    If $acK[$i][3] = 0 Then
    _GDIPlus_GraphicsDrawRect($hGraphic, $lo[1], $lo[2], $wh[1], $wh[2])
    Else
    _GDIPlus_GraphicsFillRect($hGraphic, $lo[1], $lo[2], $wh[1], $wh[2])
    EndIf
    Next
    EndFunc ;==>_draw

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

    ; Func _WinAPI_PtInRectEx()
    ; ($iX, $iY) - x, y position of the point to check
    ; ($iLeft, $iTop) - x, y position of the top left corner of rectangle
    ; ($iRight, $iBottom) - x, y position of the bottom right corner of rectangle
    Func _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iRight, $iBottom)
    Local $aResult
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", $iLeft)
    DllStructSetData($tRect, "Top", $iTop)
    DllStructSetData($tRect, "Right", $iRight)
    DllStructSetData($tRect, "Bottom", $iBottom)
    $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
    If @error Then Return SetError(@error, 0, False)
    Return $aResult[0] <> 0
    EndFunc ;==>_WinAPI_PtInRectEx
    Func _END()
    ;~ _GDIPlus_PenDispose($pBlack)
    ;~ _GDIPlus_PenDispose($pWhite)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_END

    [/autoit]

    [/spoiler]


    Habs nu so gelöst.. :D

    2 Mal editiert, zuletzt von Morrison (25. Februar 2012 um 23:17)