#include <GuiListView.au3>
Global $__g__hLVLastWnd
Global $ClassName = "Progman"
Global $hDeskTop,$hShellDll,$hWnd,$iCount,$sName,$xy
$hDeskTop = _WinAPI_FindWindowEx(Null, Null, $ClassName, Null)
While $hDeskTop <> 0
$hShellDll = _WinAPI_FindWindowEx($hDeskTop, Null, "SHELLDLL_DefView", Null)
If $hShellDll <> 0 Then ExitLoop
$hDeskTop = _WinAPI_FindWindowEx(Null, $hDeskTop, $ClassName, Null)
WEnd
$hWnd = _WinAPI_FindWindowEx($hShellDll, Null, "SysListView32", Null)
$iCount = ControlListView($hDeskTop, "", $hWnd, "GetItemCount")
For $iIndex = 0 To $iCount - 1
$sName = __GUICtrlListView_GetItemText($hWnd, $iIndex)
$xy = _GUICtrlListView_GetItemPosition($hWnd, $iIndex)
ConsoleWrite("图标位置 " & $sName & " " & $xy[0] & "," & $xy[1] & @CRLF)
Next
Func __GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem = 0)
Local $bUnicode = _GUICtrlListView_GetUnicodeFormat($hWnd)
If @OSArch == "X86" Then
Local Const $tagLVITEM = "struct;uint Mask;int Item;int SubItem;uint State;uint StateMask;ptr Text;int TextMax;int Image;lparam Param;" & _
"int Indent;int GroupID;uint Columns;ptr pColumns;ptr piColFmt;int iGroup;endstruct"
Else
Local Const $tag_LVITEM = "struct;uint Mask;int Item;int SubItem;uint State;uint StateMask;UINT64 Text;int TextMax;int Image;UINT64 Param;" & _
"int Indent;int GroupID;uint Columns;UINT64 pColumns;UINT64 piColFmt;int iGroup;endstruct"
EndIf
Local $tBuffer
If $bUnicode Then
$tBuffer = DllStructCreate("wchar Text[4096]")
Else
$tBuffer = DllStructCreate("char Text[4096]")
EndIf
Local $pBuffer = DllStructGetPtr($tBuffer)
Local $tItem = DllStructCreate($tag_LVITEM)
DllStructSetData($tItem, "SubItem", $iSubItem)
DllStructSetData($tItem, "TextMax", 4096)
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $__g__hLVLastWnd) Then
DllStructSetData($tItem, "Text", $pBuffer)
_SendMessage($hWnd, $LVM_GETITEMTEXTW, $iIndex, $tItem, 0, "wparam", "struct*")
Else
Local $iItem = DllStructGetSize($tItem)
Local $tMemMap
Local $pMemory = _MemInit($hWnd, $iItem + 4096, $tMemMap)
Local $pText = $pMemory + $iItem
DllStructSetData($tItem, "Text", $pText)
_MemWrite($tMemMap, $tItem, $pMemory, $iItem)
If $bUnicode Then
_SendMessage($hWnd, $LVM_GETITEMTEXTW, $iIndex, $pMemory, 0, "wparam", "ptr")
Else
_SendMessage($hWnd, $LVM_GETITEMTEXTA, $iIndex, $pMemory, 0, "wparam", "ptr")
EndIf
_MemRead($tMemMap, $pText, $tBuffer, 4096)
_MemFree($tMemMap)
EndIf
Else
Local $pItem = DllStructGetPtr($tItem)
DllStructSetData($tItem, "Text", $pBuffer)
If $bUnicode Then
GUICtrlSendMsg($hWnd, $LVM_GETITEMTEXTW, $iIndex, $pItem)
Else
GUICtrlSendMsg($hWnd, $LVM_GETITEMTEXTA, $iIndex, $pItem)
EndIf
EndIf
Return DllStructGetData($tBuffer, "Text")
EndFunc ;==>__GUICtrlListView_GetItemText
Func _WinAPI_FindWindowEx($hWndParent, $hWndChildAfter, $sClassName, $sWindowName)
Local $aResult = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hWndParent, "hwnd", $hWndChildAfter, "wstr", $sClassName, "wstr", $sWindowName)
If @error Then Return SetError(@error, @extended, _WinAPI_GetLastError())
Return $aResult[0]
EndFunc ;==>_WinAPI_FindWindowEx