Zu zwei: Man platziere die Slots ebenfalls auf Child-Windows und erstelle sie nach den verschiebbaren Feldern (im Skript Tiles). Dann passt das.
PARENTDRAG können nur Label und Pic, soweit ich mich erinnere. Ich habe das ganze mal ein wenig ausgebaut, mit Positionsüberprüfung. Die richtige Reihenfolge ist 1, 2, 3. Dann wird der Hintergrund grün. ![]()
#include <StaticConstants.au3>
#include <GUIConstants.au3>
;Main Window
$hMainWnd = GUICreate("Child Window Sort", 600, 400)
GUISetBkColor(0xffffff)
;Tile Windows
Global $ahTileWnd[3]
For $i = 0 To UBound($ahTileWnd) - 1
$ahTileWnd[$i] = GUICreate("", 100, 100, 0, 0, $WS_CHILD, $WS_EX_TOPMOST, $hMainWnd)
GUICtrlCreateLabel("Drag Me " & ($i + 1), 0, 0, 100, 100, $SS_CENTER + $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUISetBkColor(0xff00ff)
GUISetState()
Next
;Slot Windows
Global $ahSlotWnd[3]
For $i = 0 To UBound($ahSlotWnd) - 1
$ahSlotWnd[$i] = GUICreate("", 100, 100, 100 * ((1.5 * $i) + 1), 150, $WS_CHILD, Default, $hMainWnd)
GUICtrlCreateLabel("Slot " & ($i + 1), 0, 0, 100, 100, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0x0000ff)
GUISetState()
Next
GUISetState(@SW_SHOW, $hMainWnd) ;parent window auf sichtbar stellen
[/autoit][autoit][/autoit][autoit]While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYUP
;Linke Maustaste losgelassen
$aTilePos = AlignTiles($ahTileWnd, $ahSlotWnd)
CheckPositions($aTilePos)
EndSwitch
WEnd
Func CheckPositions($aTilePos)
;Diese Funktion entscheidet,
;ob ein Tile auf dem richtigen Slot
;liegt (bzw. ob alle richtig liegen)
;Das folgende kann man auch in eine
;Schleife packen, so ist der Sinn
;aber deutlicher
If ($aTilePos[0] = 0) And ($aTilePos[1] = 1) And ($aTilePos[2] = 2) Then
GUISetBkColor(0x00ff00, $hMainWnd)
Else
GUISetBkColor(0xff0000, $hMainWnd)
EndIf
EndFunc
Func AlignTiles($ahTileWnd, $ahSlotWnd)
;Alle Child-Windows durchgehen und schauen,
;ob eines teilweise auf dem Slot liegt
;(Stichwort: Kollisionsabfrage
Local $aReturn[UBound($ahSlotWnd)]
For $i = 0 To UBound($aReturn) - 1
$aReturn[$i] = -1
Next
;Außerdem gibt diese Funktion ein
;Array zur Bestimmung der Positionen
;zurück. Aufbau: $aReturn[n] = m
; n: Tile-Nummer
; m: Slot-Nummer
$aMainPos = WinGetPos($hMainWnd)
$aMainClientSize = WinGetClientSize($hMainWnd)
$aMainPos[0] += $aMainPos[2] - $aMainClientSize[0] - 3
$aMainPos[1] += $aMainPos[3] - $aMainClientSize[1] - 3
For $iSlot = 0 To UBound($ahSlotWnd) - 1
$aSlotPos = WinGetPos($ahSlotWnd[$iSlot])
For $iTile = 0 To UBound($ahTileWnd) - 1
$aTilePos = WinGetPos($ahTileWnd[$iTile])
If IsRectCollision($aTilePos, $aSlotPos) Then
ConsoleWrite("+DEBUG> Kollision erkannt. Richte ChildWnd " & ($iTile + 1) & " neu aus..." & @CRLF)
WinMove($ahTileWnd[$iTile], "", $aSlotPos[0] - $aMainPos[0], $aSlotPos[1] - $aMainPos[1])
$aReturn[$iTile] = $iSlot
EndIf
Next
Next
Return $aReturn
EndFunc ;==>AlignTiles
Func IsRectCollision($aPosA, $aPosB)
Local Enum $X, $Y, $W, $H
If $aPosA[$X] > ($aPosB[$X] + $aPosB[$W]) Then Return False
If ($aPosA[$X] + $aPosA[$W]) < $aPosB[$X] Then Return False
If $aPosA[$Y] > ($aPosB[$Y] + $aPosB[$H]) Then Return False
If ($aPosA[$Y] + $aPosA[$H]) < $aPosB[$Y] Then Return False
Return True
EndFunc ;==>IsRectCollision
P.S.: Das ist nicht violett, das ist pink!
Edit: Hatte vergessen, das Return-Array von AlignTiles() vorher auf unplausible Werte zu setzen.