listview控件中添加图标问题
前面请教了一个listview添加千万级数据双击弹出msgbox框时点击项变白的问题,问题已得到大侠的帮助解决,但是又一个新问题出来了,我向listview中添加数据,想根据每个数据的文件类型添加相应的图标,如图:下图是我实现的,没有显示图标:
谢谢各位大侠帮忙解决一下。
源码附件:
winapiex里有例子 回复 2# netegg
我用相关的代码实验了,只显示一个相同的图标。 。。。。。。 蛋哥威武...
蛋哥帮我解决一下这个问题:http://www.autoitx.com/thread-35166-1-1.html 回复 5# 邪恶海盗
你那个不是解决了吗 回复 6# netegg
没有啊,第二个框不知道咋整... 回复 7# 邪恶海盗
看错了,不用那个了,$str = stringsplit(_GUICtrlListView_GetItemTextstring(), '-|', 0)拆的时候,两个分隔符都有效,就直接拆开了 回复 8# netegg
应用到附件源码中,失败!!!蛋蛋兄,能否详解一下??? 回复 9# lhylm
不对呀,你这个listview根本就没设置图标样式啊 回复 10# netegg
蛋蛋兄,能否给我一个完整的源码啊(在附件源码的基础上)?我实在是搞不定。 #Include <APIConstants.au3>
#Include <GUIListView.au3>
#Include <GUIImageList.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $hForm, $Msg, $Button, $ListView, $hImageList, $hIcon, $Key, $Count = 1, $First = False
Global $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
Dim $Ext =
RegRead('HKCR\.x', '')
While 1
$Key = RegEnumKey('HKCR', $Count)
If @error Then
ExitLoop
EndIf
If StringLeft($Key, 1) = '.' Then
RegRead('HKCR\' & $Key, '')
If Abs(@error) <> 1 Then
$Ext += 1
If $Ext > UBound($Ext) - 1 Then
ReDim $Ext
EndIf
$Ext[$Ext] = $Key
EndIf
$First = 1
Else
If $First Then
ExitLoop
EndIf
EndIf
$Count += 1
WEnd
$hForm = GUICreate('MyGUI', 280, 391)
$ListView = GUICtrlCreateListView('', 10, 10, 260, 344, BitOR($LVS_DEFAULT, $LVS_NOCOLUMNHEADER), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP))
_GUICtrlListView_InsertColumn($ListView, 0, '', 238)
$hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUICtrlListView_SetImageList($ListView, $hImageList, 1)
$Button = GUICtrlCreateButton('OK', 105, 361, 70, 23)
For $i = 1 To $Ext
$hIcon = _WinAPI_ShellExtractAssociatedIcon($Ext[$i], 1)
_GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
_GUICtrlListView_AddItem($ListView, $Ext[$i], $i - 1)
_WinAPI_DestroyIcon($hIcon)
Next
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3, $Button
ExitLoop
EndSwitch
WEnd
就是#Include <WinAPIEx.au3>
_WinAPI_ShellExtractAssociatedIcon ( $sFile [, $fSmall] ) 回复 11# lhylm
老實說 我覺得這個 沒那麼簡單.....
首先 虛擬LISTVIEW實際上 並沒有 LISTVIEW
也就是說LISTVIEW 本身只是個空殼子 是個 樣式而已......
對實際的 LISTVIEW 來說資料筆數為0 或者是 一筆 但是實際的資料是放在陣列裡面的
然後..... 透過另外部分的處理 才把 資料顯示在 LISTVIEW 的位址上....
所以 你的圖標 用一般傳統的方式應該 無法設定進去....為何?? 因為 實際上LISTVIEW 裡面只有一筆或者0筆資料
你得從...... 陣列著手......也就是 $tText = DllStructCreate("wchar Text")
也就是說 你得把 圖標放在 處理圖形的部分
個人 想法而已 回复 11# lhylm
OK 了 幫你弄好了但是你的問題有兩個
1. 如何確定 你要的圖示內容我用你的 方式我一直抓不到 圖示
2. 所以我改抓 其他的圖示.....
3. 重點是 每一行的圖示都不一樣..........
範例如下: PS因為我用你的程式改的 我是用繁體系統所以中文是亂碼 不過你自己的程式你應該可以看得懂
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Local $tText = DllStructCreate("wchar Text");膘跺賦凳ㄛ蚚懂溫listview蹈杅擂
Local $GUI, $hImage,$tData1,$tData2,$iITEM_COUNT=0
Local $asPathSplit
$hGUI = GUICreate("ListView剞攜蹈桶 樓婥杅擂", 760, 400)
$hListView = GUICtrlCreateListView("Item1|nSubItem1|nSubItem2", 2, 2, 760, 294, $LVS_SHOWSELALWAYS + $LVS_OWNERDATA, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_DOUBLEBUFFER)
;扢离蹈遵
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, 240)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 1, 240)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 2, 240)
;斐膘甜壽薊芞砉蹈桶
;===================================================================
$Button1 = GUICtrlCreateButton("杅擂1", 200, 352, 73, 33)
$Button2 = GUICtrlCreateButton("杅擂2", 300, 352, 73, 33)
$Button3 = GUICtrlCreateButton("壺 ", 400, 352, 73, 33)
ok()
GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0)
;===================================================================
_FileIco()
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $Button1
Global $aData = $tData1
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button2
Global $aData = $tData2
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
; Case $Button_n
; Global $aData = 斕植杅擂踱枑腔媼峎杅郪,筍猁蛁砩峎僅狟梓猁湮衾麼脹衾ColumnCount睿itemCount
; 瘁寀剒猁GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, UBound($aData), 0)睿 AddColumn
; GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
; GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button3
Global $aData = 0
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
EndSwitch
WEnd
GUIDelete()
Exit
Func WM_NOTIFY1($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $iIDFrom, $iCode, $tInfo, $iItem, $iSubItem
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
;$Event = DllStructGetData($tagNMHDR, 3)
Switch $iIDFrom
Case $hListView
Switch $iCode
Case $LVN_GETDISPINFOA, $LVN_GETDISPINFOW ;$LVN_GETDISPINFOA = -150, $LVN_GETDISPINFOW = -177
If IsArray($aData) Then
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iItem = DllStructGetData($tInfo, "Item")
$iSubItem = DllStructGetData($tInfo, "SubItem")
If $iSubItem = 0 Then DllStructSetData($tInfo, "Image", $iItem );這邊有變動必須要變動
DllStructSetData($tText, "Text", $aData[$iItem][$iSubItem]);
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));
EndIf
Case $NM_DBLCLK;邧僻
;MsgBox(0,'',"邧僻")
Case $NM_RCLICK ; 衵僻
;MsgBox(0,'',"衵僻")
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom,$tInfo, $iItem, $iSubItem
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;恁寁莉汜岈璃腔諷璃
Case $hListView
Switch $Event; 恁寁莉汜腔岈璃
Case $LVN_GETDISPINFOA, $LVN_GETDISPINFOW
If IsArray($aData) Then
$tInfo = DllStructCreate($tagNMLVDISPINFO, $LParam)
$iItem = DllStructGetData($tInfo, "Item")
$iSubItem = DllStructGetData($tInfo, "SubItem")
If $iSubItem = 0 Then DllStructSetData($tInfo, "Image", $iItem) ;這邊有變動 必須要變動
DllStructSetData($tText, "Text", $aData[$iItem][$iSubItem]);
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));
EndIf
Case $NM_CLICK ; 酘僻
;~ ...
Case $NM_DBLCLK ; 邧僻
;MsgBox(0,'',"邧僻")
Case $NM_RCLICK ; 衵僻
;MsgBox(0,'',"邧僻")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func ok()
$openMftFile = FileOpen("file.txt", 0)
$mftRead = FileRead($openMftFile)
Global $aRecords = StringRegExp($mftRead,"(?m)(?i).*haozip[^\\]*\v?$",3)
$iITEM_COUNT = UBound($aRecords)
Global $tData1[$iITEM_COUNT], $tData2[$iITEM_COUNT], $aData
For $i = 0 To UBound($aRecords)-1
$asPathSplit = _PathSplit($aRecords[$i], $asPathSplit, $asPathSplit, $asPathSplit, $asPathSplit)
For $j = 0 To 2
Switch $j
Case 0
$tData1[$i] = $asPathSplit
Case 1
$tData1[$i] = $asPathSplit&$asPathSplit&$asPathSplit
Case 2
$tData1[$i] =$asPathSplit
EndSwitch
;$tData2[$i][$j] = ' 杅擂 2 $aData [' & $i & '][' & $j & ']'
Next
Next
EndFunc
Func _FileIco()
$hImage = _GUIImageList_Create()
_GUIImageList_SetIconSize($hImage,16,16)
For $m=0 To UBound($aRecords)-1
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", $m)
Next
_GUICtrlListView_SetImageList($hListView, $hImage,1)
EndFunc
页:
[1]
2