替换图标的图像或光标
#Include <GuiImageList.au3>
_GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon)
$hWnd | 控件句柄 |
$iIndex | 用于替换的图像索引. 如为 -1, 追加图像到列表的末尾. |
$hIcon | 图标句柄或光标指针, 其中包含新图像的位图和掩码 |
成功: | 返回图像的索引 |
失败: | 返回 -1 |
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
_Main()
Func _Main()
Local $listview, $hImage
Local $Wow64 = ""
If @AutoItX64 Then $Wow64 = "\Wow6432Node"
Local $AutoItDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir")
GUICreate("ImageList AddIcon", 410, 300)
$listview = GUICtrlCreateListView("", 2, 2, 404, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUISetState()
; 创建一个含有图像的图像列表
$hImage = _GUIImageList_Create(11, 11)
AddIcon($hImage, $AutoItDir & "\Icons\filetype1.ico")
AddIcon($hImage, $AutoItDir & "\Icons\filetype2.ico")
AddIcon($hImage, $AutoItDir & "\Icons\filetype3.ico")
_GUICtrlListView_SetImageList($listview, $hImage, 1)
; 添加列
_GUICtrlListView_AddColumn($listview, "Column 1", 100, 0, 0)
_GUICtrlListView_AddColumn($listview, "Column 2", 100, 1, 1)
_GUICtrlListView_AddColumn($listview, "Column 3", 100, 2, 2)
_GUICtrlListView_AddColumn($listview, "Column 4", 100)
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
; This is the long way to add an icon. Use _GUIImageList_AddIcon instead
Func AddIcon($hWnd, $sFile, $iIndex = 0)
Local $pIcon, $tIcon, $hIcon
$tIcon = DllStructCreate("int Icon")
$pIcon = DllStructGetPtr($tIcon)
_WinAPI_ExtractIconEx($sFile, $iIndex, 0, $pIcon, 1)
$hIcon = DllStructGetData($tIcon, "Icon")
_GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
_WinAPI_DestroyIcon($hIcon)
EndFunc ;==>AddIcon