Try something like this here: #include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
AutoItSetOption("MouseCoordMode", 2)
Global $g_hGUI, $g_hImage, $g_hGDIBitmap
Example()
Func Example()
AutoItSetOption("GUIOnEventMode", 1)
; X64 running support
Local $sWow64 = ""
If @AutoItX64 Then $sWow64 = "\Wow6432Node"
;get AutoIt install dir
Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt"
Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif"
If Not FileExists($sFile) Then
MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30)
Exit
EndIf
$g_hGUI = GUICreate("GDI+", 800, 600)
Local $iPic1 = GUICtrlCreatePic("", 20, 20, 169, 68)
Local $iPic2 = GUICtrlCreatePic("", 200, 200, 169, 68)
Local $iPic3 = GUICtrlCreatePic("", 400, 400, 169, 68)
Local $iPic4 = GUICtrlCreatePic("", 500, 500, 169, 68)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$g_hImage = _GDIPlus_ImageLoadFromFile($sFile)
$g_hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_hImage)
Local $i
For $i = 1 To 4
_WinAPI_DeleteObject(GUICtrlSendMsg(Execute("$iPic" & $i), 0x0172, $IMAGE_BITMAP, $g_hGDIBitmap)) ;$STM_SETIMAGE = 0x0172
Next
Local $aMChk, $aCtrlPos, $iDX, $iDY
Do
$aMChk = GUIGetCursorInfo($g_hGUI)
Switch $aMChk[4]
Case $iPic1
$aCtrlPos = ControlGetPos($g_hGUI, "", $iPic1)
$iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
$iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
While GUIGetCursorInfo($g_hGUI)[2]
ControlMove($g_hGUI, "", $iPic1, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY)
Sleep(20)
WEnd
Case $iPic2
$aCtrlPos = ControlGetPos($g_hGUI, "", $iPic2)
$iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
$iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
While GUIGetCursorInfo($g_hGUI)[2]
ControlMove($g_hGUI, "", $iPic2, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY)
Sleep(20)
WEnd
Case $iPic3
$aCtrlPos = ControlGetPos($g_hGUI, "", $iPic3)
$iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
$iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
While GUIGetCursorInfo($g_hGUI)[2]
ControlMove($g_hGUI, "", $iPic3, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY)
Sleep(20)
WEnd
Case $iPic4
$aCtrlPos = ControlGetPos($g_hGUI, "", $iPic4)
$iDX = Abs(MouseGetPos(0) - $aCtrlPos[0])
$iDY = Abs(MouseGetPos(1) - $aCtrlPos[1])
While GUIGetCursorInfo($g_hGUI)[2]
ControlMove($g_hGUI, "", $iPic4, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY)
Sleep(20)
WEnd
EndSwitch
Until Not Sleep(50)
EndFunc ;==>Example
Func _Exit()
_WinAPI_DeleteObject($g_hGDIBitmap)
_GDIPlus_ImageDispose($g_hImage)
_GDIPlus_Shutdown()
GUIDelete($g_hGUI)
Exit
EndFunc ;==>_Exit There is room for optimizations!