#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
$Gui = GUICreate("Test by-3mile", 800, 600, Default, Default)
$listview = _GUICtrlListView_Create($Gui, "a", 2, 2, 798, 598, BitOR($LVS_NOCOLUMNHEADER, $LVS_ICON, $LVS_SINGLESEL), -1, True)
$iTotalNumber = DllCall("Shell32.dll", "long", "ExtractIcon", "ptr", 0, "str", "Shell32.dll", "int", -1)
$Image = _GUIImageList_Create(16, 16, 5, 1);通常我是用这里来调整图标多少的
For $i = 1 To $iTotalNumber[0]
__GUIImageList_AddIcon($Image, "c:\WINDOWS\system32\shell32.dll", $i)
_GUICtrlListView_SetImageList($listview, $Image, 0)
_GUICtrlListView_AddItem($listview, "第" & $i & "个", $i - 1)
Next
_GUICtrlListView_SetBkImage($listview, @ScriptDir & "\BkgPic.jpg", 1)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While GUIGetMsg() + 3
WEnd
Func __Icons_Icon_Extract($sIcon, $iIndex, $iWidth, $iHeight)
Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
If (@error) Or ($Ret[0] = 0) Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[5]
EndFunc ;==>__Icons_Icon_Extract
Func __GUIImageList_AddIcon($hWnd, $sFile, $iIndex = 0)
Local $iRet
$iRet = __Icons_Icon_Extract($sFile, $iIndex, _GUIImageList_GetIconWidth($hWnd), _GUIImageList_GetIconHeight($hWnd))
If $iRet <= 0 Then Return SetError(-1, $iRet, 0)
Local $hIcon = $iRet
$iRet = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
_WinAPI_DestroyIcon($hIcon)
If $iRet = -1 Then Return SetError(-2, $iRet, 0)
Return $iRet
EndFunc ;==>__GUIImageList_AddIcon
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $Menu
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $listview
Switch $iCode
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "SubItem")
If $Index > -1 Then
$L_Name = _GUICtrlListView_GetItemText($hWndFrom, $Index)
MsgBox(4096, "响应双击", "你选择的是 " & $L_Name)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|