#include-once ;~ #include "Memory.au3" ;~ #include "WinAPIInternals.au3" ; #INDEX# ======================================================================================================================= ; Title .........: GUI Ctrl Extended UDF Library for AutoIt3 ; AutoIt Version : 3.3.17.0 ; Description ...: Functions that assist with _GUI control management. ; Author(s) .....: jpm ; =============================================================================================================================== #Region Global Variables and Constants ; #VARIABLES# =================================================================================================================== Global $__g_hGUICtrl_LastWnd ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== ; =============================================================================================================================== #EndRegion Global Variables and Constants #Region Functions list ; #CURRENT# ===================================================================================================================== ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; __GUICtrl_SendMsg ; __GUICtrl_SendMsg_Init ; __GUICtrl_SendMsg_InProcess ; __GUICtrl_SendMsg_OutProcess ; __GUICtrl_SendMsg_Internal ; ; __GUICtrl_TagOutProcess ; =============================================================================================================================== #EndRegion Functions list ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_SendMsg ; Description ...: _SendMessage() wrapper for handling In or out process ; Syntax.........: __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer, $bRetItem, $iElement, $bRetBuffer, $iElementMAX) ; Parameters ....: $hWnd - Handle of the control ; $iMsg - SendMessage Msg value ; $iIndex - index of the Item ; $tItem - Struct of the Item ; $tBuffer - Struct to contain return chars ; $bRetItem - tItem must be return ; $iElement - index of the element ; $bRetBuffer - tBuffer must be return ; $iElementMax - index of the MAX element ; Return values .: result of the SendMessage ; Author ........: Jpm ; Modified ......: ; Remarks .......: ; Related .......: _GUICtrlListView_GetItemEx, _GUICtrlListView_GetItemText, __GUICtrlListView_Sort ; =============================================================================================================================== Func __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement) If $iElement > 0 Then DllStructSetData($tItem, $iElement, DllStructGetPtr($tBuffer)) If $iElement = $iElementMax Then DllStructSetData($tItem, $iElement + 1, DllStructGetSize($tBuffer)) EndIf Local $iRet If IsHWnd($hWnd) Then If DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0)[2] = @AutoItPID Then ; _WinAPI_InProcess $iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "struct*", $tItem)[0] Else Local $iItem = Ceiling(DllStructGetSize($tItem) / 16) * 16 ; to allocate buffer on a 16 byte boundary Local $tMemMap, $pText Local $iBuffer = 0 If ($iElement > 0) Or ($iElementMax = 0) Then $iBuffer = DllStructGetSize($tBuffer) Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap) If $iBuffer Then $pText = $pMemory + $iItem If $iElementMax >= 0 Then DllStructSetData($tItem, $iElement, $pText) Else $iIndex = $pText EndIf _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer) EndIf _MemWrite($tMemMap, $tItem, $pMemory, $iItem) $iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "ptr", $pMemory)[0] If $iBuffer And $bRetBuffer Then _MemRead($tMemMap, $pText, $tBuffer, $iBuffer) If $bRetItem Then _MemRead($tMemMap, $pMemory, $tItem, $iItem) _MemFree($tMemMap) EndIf Else $iRet = GUICtrlSendMsg($hWnd, $iMsg, $iIndex, DllStructGetPtr($tItem)) EndIf Return $iRet EndFunc ;==>__GUICtrl_SendMsg ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_SendMsg_Init ; Description ...: Split of __GUICtrl_SendMsg() to be use if looping is required ; Syntax.........: __GUICtrl_SendMsg($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer, $bRetItem, $iElement, $bRetBuffer, $iElementMAX) ; Parameters ....: $hWnd - Handle of the control ; $iMsg - SendMessage Msg value ; $iIndex - index of the Item ; $tItem - Struct of the Item ; $tBuffer - Struct to contain return chars ; $bRetItem - tItem must be return ; $iElement - index of the element ; $bRetBuffer - tBuffer must be return ; $iElementMax - index of the MAX element ; Return values .: ptr to function __GUICtrl_SendMsg_* according to $hWnd type ; Author ........: Jpm ; Modified ......: ; Remarks .......: ; Related .......: __GUICtrl_SendMsg_InProcess, __GUICtrl_SendMsg_OutProcess, __GUICtrl_SendMsg_Internal ; =============================================================================================================================== Func __GUICtrl_SendMsg_Init($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement) #forceref $iMsg, $iIndex, $bRetItem, $bRetBuffer DllStructSetData($tItem, $iElement, DllStructGetPtr($tBuffer)) If $iElement = $iElementMax Then DllStructSetData($tItem, $iElement + 1, DllStructGetSize($tBuffer)) Local $pFunc If IsHWnd($hWnd) Then If DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0)[2] = @AutoItPID Then ; _WinAPI_InProcess $pFunc = __GUICtrl_SendMsg_InProcess SetExtended(1) Else $pFunc = __GUICtrl_SendMsg_OutProcess SetExtended(2) EndIf Else $pFunc = __GUICtrl_SendMsg_Internal SetExtended(3) EndIf Return $pFunc EndFunc ;==>__GUICtrl_SendMsg_Init ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_SendMsg_InProcess ; Description ...: Split of __GUICtrl_SendMsg() to be use for InProcess ; Syntax.........: __GUICtrl_SendMsg_InProcess($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer, $bRetItem, $iElement, $bRetBuffer, $iElementMAX) ; Parameters ....: $hWnd - Handle of the control ; $iMsg - SendMessage Msg value ; $iIndex - index of the Item ; $tItem - Struct of the Item ; $tBuffer - Struct to contain return chars ; $bRetItem - tItem must be return ; $iElement - index of the element ; $bRetBuffer - tBuffer must be return ; $iElementMax - index of the MAX element ; Return values .: result of the SendMessage ; Author ........: Jpm ; Modified ......: ; Remarks .......: ; Related .......: __GUICtrl_SendMsg_Init ; =============================================================================================================================== Func __GUICtrl_SendMsg_InProcess($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement) #forceref $tBuffer, $bRetItem, $bRetBuffer, $iElementMax Return DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "struct*", $tItem)[0] EndFunc ;==>__GUICtrl_SendMsg_InProcess ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_SendMsg_OutProcess ; Description ...: Split of __GUICtrl_SendMsg() to be use for OutProcess ; Syntax.........: __GUICtrl_SendMsg_InProcess($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer, $bRetItem, $iElement, $bRetBuffer, $iElementMAX) ; Parameters ....: $hWnd - Handle of the control ; $iMsg - SendMessage Msg value ; $iIndex - index of the Item ; $tItem - Struct of the Item ; $tBuffer - Struct to contain return chars ; $bRetItem - tItem must be return ; $iElement - index of the element ; $bRetBuffer - tBuffer must be return ; $iElementMax - index of the MAX element ; Return values .: result of the SendMessage ; Author ........: Jpm ; Modified ......: ; Remarks .......: ; Related .......: __GUICtrl_SendMsg_Init ; =============================================================================================================================== Func __GUICtrl_SendMsg_OutProcess($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement) Local $iItem = DllStructGetSize($tItem) Local $tMemMap, $pText Local $iBuffer = 0 If ($iElement > 0) Or ($iElementMax = 0) Then $iBuffer = DllStructGetSize($tBuffer) Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap) If $iBuffer Then $pText = $pMemory + $iItem If $iElementMax Then DllStructSetData($tItem, $iElement, $pText) Else $iIndex = $pText EndIf _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer) EndIf _MemWrite($tMemMap, $tItem, $pMemory, $iItem) Local $iRet = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $iIndex, "ptr", $pMemory)[0] If $iBuffer And $bRetBuffer Then _MemRead($tMemMap, $pText, $tBuffer, $iBuffer) If $bRetItem Then _MemRead($tMemMap, $pMemory, $tItem, $iItem) _MemFree($tMemMap) Return $iRet EndFunc ;==>__GUICtrl_SendMsg_OutProcess ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_SendMsg_Internal ; Description ...: Split of __GUICtrl_SendMsg() to be use for id Control ; Syntax.........: __GUICtrl_SendMsg_Internal($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer, $bRetItem, $iElement, $bRetBuffer, $iElementMAX) ; Parameters ....: $hWnd - Handle of the control ; $iMsg - SendMessage Msg value ; $iIndex - index of the Item ; $tItem - Struct of the Item ; $tBuffer - Struct to contain return chars ; $bRetItem - tItem must be return ; $iElement - index of the element ; $bRetBuffer - tBuffer must be return ; $iElementMax - index of the MAX element ; Return values .: result of the SendMessage ; Author ........: Jpm ; Modified ......: ; Remarks .......: ; Related .......: __GUICtrl_SendMsg_Init ; =============================================================================================================================== Func __GUICtrl_SendMsg_Internal($hWnd, $iMsg, $iIndex, ByRef $tItem, $tBuffer = 0, $bRetItem = False, $iElement = -1, $bRetBuffer = False, $iElementMax = $iElement) #forceref $tBuffer, $bRetItem, $bRetBuffer, $iElementMax Return GUICtrlSendMsg($hWnd, $iMsg, $iIndex, DllStructGetPtr($tItem)) EndFunc ;==>__GUICtrl_SendMsg_Internal ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GUICtrl_TagOutProcess ; Description ...: Convert ptr when use with an OutProcess control ; Syntax.........: __GUICtrl_TagOutProcess($hWnd, ByRef $sTag) ; Parameters ....: $hWnd - Handle of the control ; $sTag - £tag to be updated ; Return values .: None ; Author ........: Danyfirex,Jpm ; Modified ......: ; Remarks .......: ; Related .......: _GUICtrlTab_GetItem, ... ; =============================================================================================================================== Func __GUICtrl_TagOutProcess($hWnd, ByRef $sTag) Local $bIsWow64 = _WinAPI_IsWow64Process(DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $hWnd, "dword*", 0)[2]) ;x86 read remote x64 If Not (@AutoItX64 Or $bIsWow64) Then $sTag = StringRegExpReplace($sTag, "(dword_ptr)|(uint_ptr)|(int_ptr)|(ptr)|(lparam)|(wparam)|(hwnd)|(handle)", "UINT64") EndIf ;x64 read remote x86 If @AutoItX64 And $bIsWow64 Then $sTag = StringRegExpReplace($sTag, "(dword_ptr)|(uint_ptr)|(int_ptr)|(ptr)|(lparam)|(wparam)|(hwnd)|(handle)", "UINT") EndIf EndFunc ;==>__GUICtrl_TagOutProcess