I finally got it to work. I just replaced the gethotitem with hittest. The code is below.
Code:
#Include TaskButton.ahk
~LButton::
MouseGetPos, , , id
WinGetClass, Class, ahk_id %id%
if(Class != "Shell_TrayWnd")
return
StartPos := HitTest()
return
~LButton Up::
MouseGetPos, , , id
WinGetClass, Class, ahk_id %id%
if(Class != "Shell_TrayWnd")
return
MoveButton(StartPos, HitTest())
return
HitTest()
{
idxTB:= GetTaskSwBar()
ControlGet, hWnd, hWnd,, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd
WinGet, pid, PID, ahk_id %hWnd%
hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pid)
pRB := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 8, "Uint", 0x1000, "Uint", 0x4)
DllCall("GetCursorPos", "int64P", pt)
DllCall("ScreenToClient", "Uint", hWnd, "int64P", pt)
DllCall("WriteProcessMemory", "Uint", hProc, "Uint", pRB, "int64P", pt, "Uint", 8, "Uint", 0)
idx := DllCall("SendMessage", "Uint", hWnd, "Uint", 0x445, "Uint", 0, "Uint", pRB) ; TB_HITTEST
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle" , "Uint", hProc)
Return idx
}