Hallo,
ich versuche für mein Projekt ein Rechteck mit den Pfeiltasten bewegen zu lassen, leider schaff ich des nicht..ich hoffe auf Eure Hilfe!
Danke!
Spoiler anzeigen
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
$dll = DllOpen("user32.dll")
Opt("GUIOnEventMode", 1)
#region ### START Koda GUI section ### Form=c:\dokumente und einstellungen\besitzer\desktop\au3\lupe.kxf
$Form1 = GUICreate("Form1", 422, 255, 286, 196)
GUISetState($WS_EX_TOPMOST)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Slider1 = GUICtrlCreateSlider(32, 56, 150, 45)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetLimit($Slider1, 100, 0)
GUICtrlSetData($Slider1, 50)
;GUICtrlSetOnEvent(-1, "Slider1Change")
$Slider2 = GUICtrlCreateSlider(32, 152, 150, 45)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetLimit($Slider2, 100, 0)
GUICtrlSetData($Slider2, 50)
;GUICtrlSetOnEvent(-1, "Slider2Change")
$Input1 = GUICtrlCreateInput("", 224, 32, 150, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetOnEvent(-1, "Input1Change")
$Label1 = GUICtrlCreateLabel("Koordinaten:", 224, 15, 64, 17)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Label1Click")
$Label2 = GUICtrlCreateLabel("x - Achse", 40, 40, 48, 17)
GUICtrlSetOnEvent(-1, "Label2Click")
$Label3 = GUICtrlCreateLabel("y - Achse", 40, 136, 48, 17)
GUICtrlSetOnEvent(-1, "Label3Click")
;$Label4 = GUICtrlCreateLabel("", 224, 64, 150, 150)
;GUICtrlSetOnEvent(-1, "Label4Click")
#endregion ### END Koda GUI section ###
;$hDesktop = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $GUI_BKCOLOR_TRANSPARENT))
Dim $iX1o, $iY1o, $iX2o, $iY2o, $iX1u, $iY1u, $iX2u, $iY2u, $iX1l, $iY1l, $iX2l, $iY2l, $iX1r, $iY1r, $iX2r, $iY2r
Local $hDC, $hPen, $obj_orig
$width = 1
$color = 0xFF
$hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
$hPen = _WinAPI_CreatePen($PS_SOLID, $width, $color)
$obj_orig = _WinAPI_SelectObject($hDC, $hPen)
Dim $coordLR, $coordHR, $countLR, $countHR, $ok
$dist = 5
$Scale = 30
$sl1 = 50
$sl2 = 50
Dim $Lay[$Scale + 1][$Scale + 1]
Dim $PosOld[2]
For $x = 1 To $Scale
For $y = 1 To $Scale
$Lay[$x][$y] = GUICtrlCreateLabel("", 224 + $x * 5, 64 + $y * 5, 5, 5, $SS_RIGHT);, BitOR($SS_BLACKRECT, $SS_WHITERECT)) entweder schwarz oder weiss
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT);
Next
Next
GUISetState(@SW_SHOW)
HotKeySet("{ESC}", "_Exit")
;Start GUI Schleife
While 1
$Pos = MouseGetPos()
For $x = 1 To $Scale
For $y = 1 To $Scale
$Pix = PixelGetColor(($Pos[0] + $coordLR) + $x - ($Scale / 2), ($Pos[1] + $coordHR) + $y - ($Scale / 2))
GUICtrlSetBkColor($Lay[$x][$y], $Pix)
Next
Next
;wenn Pfeiltasten gedrückt
If _IsPressed('25', $dll) Then ;links gedrückt
$countLR = $countLR + (-1)
$coordLR = $coordLR - $dist
$sl1 = $sl1 - 10
$iX1o = $iX1o - $dist
$iY1o = $iY1o
$iX2o = $iX2o - $dist
$iY2o = $iY2o
$iX1u = $iX1u - $dist
$iY1u = $iY1u
$iX2u = $iX2u - $dist
$iY2u = $iY2u
$iX1l = $iX1l - $dist
$iY1l = $iY1l
$iX2l = $iX2l - $dist
$iY2l = $iY2l
$iX1r = $iX1r - $dist
$iY1r = $iY1r
$iX2r = $iX2r - $dist
$iY2r = $iY2r
GUICtrlSetData($Slider1, $sl1)
ElseIf _IsPressed('27', $dll) Then ;rechts gedrückt
$countLR = $countLR + 1
$coordLR = $coordLR + $dist
$sl1 = $sl1 + 10
;_WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)
;$iX1 X Koordinate des Startpunkts der Linie.
;$iY1 Y Koordinate des Startpunkts der Linie.
;$iX2 X Koordinate des Endpunkts der Linie.
;$iY2 Y Koordinate des Endpunkts der Linie.
$iX1o = $iX1o + $dist
$iY1o = $iY1o
$iX2o = $iX2o + $dist
$iY2o = $iY2o
$iX1u = $iX1u + $dist
$iY1u = $iY1u
$iX2u = $iX2u + $dist
$iY2u = $iY2u
$iX1l = $iX1l + $dist
$iY1l = $iY1l
$iX2l = $iX2l + $dist
$iY2l = $iY2l
$iX1r = $iX1r + $dist
$iY1r = $iY1r
$iX2r = $iX2r + $dist
$iY2r = $iY2r
GUICtrlSetData($Slider1, $sl1)
ElseIf _IsPressed('26', $dll) Then ;hoch gedrückt
$countHR = $countHR + (-1)
$coordHR = $coordHR - $dist
$sl2 = $sl2 - 10
$iX1o = $iX1o - $dist
$iY1o = $iY1o
$iX2o = $iX2o - $dist
$iY2o = $iY2o
$iX1u = $iX1u - $dist
$iY1u = $iY1u
$iX2u = $iX2u - $dist
$iY2u = $iY2u
$iX1l = $iX1l - $dist
$iY1l = $iY1l
$iX2l = $iX2l - $dist
$iY2l = $iY2l
$iX1r = $iX1r - $dist
$iY1r = $iY1r
$iX2r = $iX2r - $dist
$iY2r = $iY2r
GUICtrlSetData($Slider2, $sl2)
ElseIf _IsPressed('28', $dll) Then ;runter gedrückt
$countHR = $countHR + 1
$coordHR = $coordHR + $dist
$sl2 = $sl2 + 10
$iX1o = $iX1o + $dist
$iY1o = $iY1o
$iX2o = $iX2o + $dist
$iY2o = $iY2o
$iX1u = $iX1u + $dist
$iY1u = $iY1u
$iX2u = $iX2u + $dist
$iY2u = $iY2u
$iX1l = $iX1l + $dist
$iY1l = $iY1l
$iX2l = $iX2l + $dist
$iY2l = $iY2l
$iX1r = $iX1r + $dist
$iY1r = $iY1r
$iX2r = $iX2r + $dist
$iY2r = $iY2r
GUICtrlSetData($Slider2, $sl2)
EndIf
;wenn Mausbewegung
If $Pos[0] <> $PosOld[0] Or $Pos[1] <> $PosOld[1] Then
$coordHR = 0
$coordLR = 0
$countHR = 0
$countLR = 0
$PosOld = $Pos
GUICtrlSetData($Slider1, 50)
GUICtrlSetData($Slider2, 50)
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
EndIf
;_WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)
;$iX1 X Koordinate des Startpunkts der Linie.
;$iY1 Y Koordinate des Startpunkts der Linie.
;$iX2 X Koordinate des Endpunkts der Linie.
;$iY2 Y Koordinate des Endpunkts der Linie.
_WinAPI_DrawLine($hDC, $Pos[0] - $iX1o , $Pos[1] - $iY1o, $Pos[0] + $iX2o, $Pos[1] - $iY2o) ; oben
_WinAPI_DrawLine($hDC, $Pos[0] - $iX1u , $Pos[1] + $iY1u, $Pos[0] + $iX2u, $Pos[1] + $iY2u) ; untel
_WinAPI_DrawLine($hDC, $Pos[0] + $iX1r , $Pos[1] - $iY1r, $Pos[0] + $iX2r, $Pos[1] + $iY2r) ; rechts
_WinAPI_DrawLine($hDC, $Pos[0] - $iX1l , $Pos[1] - $iY1l, $Pos[0] - $iX2l, $Pos[1] + $iY2l) ; links
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] - 15, $Pos[0] + 16, $Pos[1] - 15) ; oben
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] + 16, $Pos[0] + 16, $Pos[1] + 16) ; untel
;~ _WinAPI_DrawLine($hDC, $Pos[0] + 16 , $Pos[1] - 15, $Pos[0] + 16, $Pos[1] + 16) ; rechts
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] - 15, $Pos[0] - 15, $Pos[1] + 16) ; links
ToolTip($countLR & ', ' & $countHR)
GUICtrlSetData($Input1, 'Maus: x=' & $Pos[0] & ', y=' & $Pos[1]); & ' Bild: x=' & $Pos[0] + ($Scale / 2) & ', y=' & $Pos[1] + ($Scale / 2))
Sleep(100)
WEnd
Func Form1Close()
_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)
Exit
EndFunc ;==>Form1Close
Func Form1Maximize()
EndFunc ;==>Form1Maximize
Func Form1Minimize()
EndFunc ;==>Form1Minimize
Func Form1Restore()
EndFunc ;==>Form1Restore
Func Input1Change()
EndFunc ;==>Input1Change
Func Label1Click()
EndFunc ;==>Label1Click
Func Label2Click()
EndFunc ;==>Label2Click
Func Label3Click()
EndFunc ;==>Label3Click
Func Label4Click()
EndFunc ;==>Label4Click
Func Slider1Change()
EndFunc ;==>Slider1Change
Func Slider2Change()
EndFunc ;==>Slider2Change
;~ Func Auswahl()
;~ ;Auswahlrechteck zeichnen
;~ ; X des Startpunkts der Linie./Y des Startpunkts der Linie./X des Endpunkts der Linie./Y des Endpunkts der Linie.
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] - 15, $Pos[0] + 16, $Pos[1] - 15) ; oben
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] + 16, $Pos[0] + 16, $Pos[1] + 16) ; untel
;~ _WinAPI_DrawLine($hDC, $Pos[0] + 16 , $Pos[1] - 15, $Pos[0] + 16, $Pos[1] + 16) ; rechts
;~ _WinAPI_DrawLine($hDC, $Pos[0] - 15 , $Pos[1] - 15, $Pos[0] - 15, $Pos[1] + 16) ; links
;~ EndFunc
Func _Exit()
_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)
Exit
EndFunc ;==>_Exit