来自 https://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=73458&pid=768770&fromuid=7658885 。
命名为 DesktopShortcuts.au3 保存在 %AutoIt3%\Include里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#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") Func DesktopShortcuts() Local $shortcuts[$iCount] For $iIndex = 0 To $iCount - 1 $sName = __GUICtrlListView_GetItemText($hWnd, $iIndex) $xy = _GUICtrlListView_GetItemPosition($hWnd, $iIndex) ;ConsoleWrite("图标位置 " & $sName & " " & $xy[0] & "," & $xy[1] & @CRLF) Local $gItem[3] $gItem[0] = $sName $gItem[1] = $xy[0] $gItem[2] = $xy[1] $shortcuts[$iIndex] = $gItem Next Return $shortcuts EndFunc 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 |
使用:
1 2 3 4 5 6 7 8 9 10 11 |
#include <DesktopShortcuts.au3> Local $shortcuts = DesktopShortcuts() Local $iRows = UBound($shortcuts) For $i = 0 To $iRows - 1 Local $item = $shortcuts[$i] $name = $item[0] $x = $item[1] $y = $item[2] ConsoleWrite("图标:" & $name & ",x=" & $x & ",y=" & $y & @CRLF) ; iconList -1 Next |
- end
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/4450.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设