GDI+ Anfangsscript mit "Wand"

  • Huhu, mein erstes GDI+ Script !!!


    Bewegen mit den Pfeiltasten, das orangene 4eck ist wie eine Mauer

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    _GDIPlus_Startup()
    Global $ObjectPos1 = 100, $ObjectPos2 = 100, $ObjectPos3 = 50, $ObjectPos4 = 50
    HotKeySet("{LEFT}", "_BewegenLinks")
    HotKeySet("{RIGHT}", "_BewegenRechts")
    HotKeySet("{UP}", "_BewegenOben")
    HotKeySet("{DOWN}", "_BewegenUnten")
    Global $GUIWidth = 600, $GUIHeight = 400
    Global $Pos1 = 0 , $Pos2 = 0
    Global $GUI_Back_Color = 0xFF000000 + 0xECE9D8
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("EMs Journy of GDI+", 600, 400, 192, 124)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $Graphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $Graphic)
    $Backbuffer = _GDIPlus_ImageGetGraphicsContext($Bitmap);Kreirt 2te Bitmap die dann auf Front Buffer übertragen wird
    $Pen = _GDIPlus_PenCreate(0xFFFFA147)
    $Brush = _GDIPlus_BrushCreateSolid(0xFFFFA147)
    _GDIPlus_GraphicsFillRect($Graphic, 100, 100, 50, 50, $Brush)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Exit()
    Exit

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

    EndSwitch
    _ReDraw()
    WEnd
    Func _BewegenLinks()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color) ;Macht alles "Sauber"
    If ($Pos1-50) <= 0 Then
    $Pos1 = $GUIWidth
    EndIf
    If $Pos1-50 = 100 and $Pos2 = 100 Then
    Else
    $Pos1 -= 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc
    Func _BewegenRechts()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos1+50) >= $GUIWidth Then
    $Pos1 = -50
    EndIf
    If $Pos1+50 = 100 and $Pos2 = 100 Then
    Else
    $Pos1 += 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc
    Func _BewegenOben()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos2-50) <= 0 Then
    $Pos2 = $GUIHeight
    EndIf
    If $Pos2-50 = 100 and $Pos1 = 100 Then
    Else
    $Pos2 -= 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc
    Func _BewegenUnten()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos2+50) >= $GUIHeight Then
    $Pos2 = -50
    EndIf
    If $Pos2+50 = 100 and $Pos1 = 100 Then
    Else
    $Pos2 += 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc
    Func _Exit()
    _GDIPlus_Shutdown()
    _GDIPlus_ShutDown()
    _GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_PenDispose($Pen)
    _GDIPlus_BrushDispose($Brush)
    EndFunc
    Func _ReDraw()
    _GDIPlus_GraphicsFillRect($Graphic, 100, 100, 50, 50, $Brush)
    EndFunc

    [/autoit]

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • 1. Warum machst du zweimal Shutdown?
    2. Mach das Shutdown erst, nachdem du alles "disposed" hast!
    3. Den Backbuffer "disposen" mit _GDIPlus_GraphicsDispose()

    Warum erstellst du ein Fenster ohne alles mit Koda???

    So, das sieht zwar schon mal ganz gut aus, allerdings Frage ich mich, warum du dieses Viereck in Stufen bewegst.


    Also: Auf jeden Fall dein Skript verbessern!!! Und räum es etwas aus.

  • Hier, so sieht das Skript doch gleich mal viel schöner aus:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

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

    _GDIPlus_Startup()

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

    Global $ObjectPos1 = 100, $ObjectPos2 = 100, $ObjectPos3 = 50, $ObjectPos4 = 50

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

    HotKeySet("{LEFT}", "_BewegenLinks")
    HotKeySet("{RIGHT}", "_BewegenRechts")
    HotKeySet("{UP}", "_BewegenOben")
    HotKeySet("{DOWN}", "_BewegenUnten")

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

    Global $GUIWidth = 600, $GUIHeight = 400
    Global $Pos1 = 0, $Pos2 = 0
    Global $GUI_Back_Color = 0xFF000000 + 0xECE9D8

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

    Global $Form1 = GUICreate("EMs Journy of GDI+", 600, 400, -1, -1)
    GUISetState(@SW_SHOW)

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

    Global $Graphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
    Global $Bitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $Graphic)
    Global $Backbuffer = _GDIPlus_ImageGetGraphicsContext($Bitmap);Kreirt 2te Bitmap die dann auf Front Buffer übertragen wird
    Global $Pen = _GDIPlus_PenCreate(0xFFFFA147)
    Global $Brush = _GDIPlus_BrushCreateSolid(0xFFFFA147)

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

    _GDIPlus_GraphicsFillRect($Graphic, 100, 100, 50, 50, $Brush)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Exit()
    Exit
    EndSwitch
    _ReDraw()
    WEnd

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

    Func _BewegenLinks()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color) ;Macht alles "Sauber"
    If ($Pos1 - 50) <= 0 Then
    $Pos1 = $GUIWidth
    EndIf
    If $Pos1 - 50 = 100 And $Pos2 = 100 Then
    Else
    $Pos1 -= 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc ;==>_BewegenLinks

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

    Func _BewegenRechts()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos1 + 50) >= $GUIWidth Then
    $Pos1 = -50
    EndIf
    If $Pos1 + 50 = 100 And $Pos2 = 100 Then
    Else
    $Pos1 += 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc ;==>_BewegenRechts

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

    Func _BewegenOben()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos2 - 50) <= 0 Then
    $Pos2 = $GUIHeight
    EndIf
    If $Pos2 - 50 = 100 And $Pos1 = 100 Then
    Else
    $Pos2 -= 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc ;==>_BewegenOben

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

    Func _BewegenUnten()
    _GDIPlus_GraphicsClear($Backbuffer, $GUI_Back_Color)
    If ($Pos2 + 50) >= $GUIHeight Then
    $Pos2 = -50
    EndIf
    If $Pos2 + 50 = 100 And $Pos1 = 100 Then
    Else
    $Pos2 += 50
    _GDIPlus_GraphicsDrawRect($Backbuffer, $Pos1, $Pos2, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($Graphic, $Bitmap, 0, 0, $GUIWidth, $GUIHeight)
    EndIf
    EndFunc ;==>_BewegenUnten

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

    Func _Exit()
    _GDIPlus_GraphicsDispose($Graphic)
    _GDIPlus_GraphicsDispose($Backbuffer)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_PenDispose($Pen)
    _GDIPlus_BrushDispose($Brush)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Exit

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

    Func _ReDraw()
    _GDIPlus_GraphicsFillRect($Graphic, 100, 100, 50, 50, $Brush)
    EndFunc ;==>_ReDraw

    [/autoit]

    Und statt Hotkeys würde ich die Funktion

    [autoit]


    #include <Misc.au3>

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

    _IsPressed()

    [/autoit]
  • Np:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <GUIConstants.au3>

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

    Global $iWidth = 500
    Global $iHeight = 500
    Global $iPfad = ; <<<<< Schreib hier den Pfad des Bildes hin >>>>>>>>>>>

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

    Global $hGui = GUICreate("", $iWidth, $iHeight)
    GUISetState()

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

    _GDIPlus_Startup()

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

    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    Global $hBild = _GDIPlus_ImageLoadFromFile($iPfad)

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

    _GDIPlus_GraphicsDrawImageRect($hBuffer, $hBild, 0, 0, $iWidth, $iHeight) ; Kannst die Werte später wieder ändern

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

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Exit()
    EndSwitch
    WEnd

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

    Func _Exit()
    _GDIPlus_ImageDispose($hBild)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]