如何双击替换 GUICtrlCreateListView 内某一项目的图片![已解决]
本帖最后由 病毒专收员 于 2013-3-20 15:06 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Form2 = GUICreate("窗体1", 1001, 674, 14, 32)
$Group1 = GUICtrlCreateGroup("", -1, 8, 1001, 449)
$ListView1 = GUICtrlCreateListView("", 3, 18, 993, 435)
GUICtrlSetStyle($ListView1, $LVS_ICON)
$Group2 = GUICtrlCreateGroup("操作日志", 0, 456, 1000, 217)
$ListView2 = GUICtrlCreateListView("", 3, 472, 993, 198)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_load1()
;~ Sleep(2000)
;~ _load2()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Load1()
Local $hImage, $var, $i, $path, $error, $hFile, $path1, $path2
For $i = 1 To 10 Step 1
$hImage = _GUIImageList_Create(32, 32, 5, 1)
_GUIImageList_AddBitmap($hImage, @ScriptDir & "\闲.bmp")
_GUICtrlListView_SetImageList($listview1, $hImage, 0)
_GUICtrlListView_AddItem($listview1, "test"&$i, 0)
Next
EndFunc ;==>_Load
;~
Func _Load2()
EndFunc ;==>_Load
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
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 $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
MsgBox(0, "", "未选定")
Return
EndIf
MsgBox(0,0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
Case $NM_RCLICK ; 右击
MsgBox(0,0,"点了右键")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
用的图片是 32*32的,bmp格式的。
求解······ #Include <GuiListView.au3>
_GUICtrlListView_SetItemImage($hWnd, $iIndex, $iImage[, $iSubItem = 0]) #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Form2 = GUICreate("窗体1", 1001, 674, 14, 32)
$Group1 = GUICtrlCreateGroup("", -1, 8, 1001, 449)
$ListView1 = GUICtrlCreateListView("", 3, 18, 993, 435)
GUICtrlSetStyle($ListView1, $LVS_ICON)
$Group2 = GUICtrlCreateGroup("操作日志", 0, 456, 1000, 217)
$ListView2 = GUICtrlCreateListView("", 3, 472, 993, 198)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_load1()
;~ Sleep(2000)
;~ _load2()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Load1()
Local $hImage, $var, $i, $path, $error, $hFile, $path1, $path2
For $i = 1 To 10 Step 1
$hImage = _GUIImageList_Create(32, 32, 5, 1)
_GUIImageList_AddBitmap($hImage, @ScriptDir & "\闲.bmp")
_GUIImageList_AddBitmap($hImage, @ScriptDir & "\忙.bmp")
_GUICtrlListView_SetImageList($ListView1, $hImage, 0)
_GUICtrlListView_AddItem($ListView1, $i, 0)
Next
EndFunc ;==>_Load1
;~
Func _Load2()
EndFunc ;==>_Load2
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
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 $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If _GUICtrlListView_GetItemImage($ListView1, Number($Index)) Then
_GUICtrlListView_SetItemImage($ListView1, Number($Index), 0)
Else
_GUICtrlListView_SetItemImage($ListView1, Number($Index), 1)
EndIf
Case $NM_RCLICK ; 右击
MsgBox(0, 0, "点了右键")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
haijie1223 发表于 2013-3-20 08:26 http://www.autoitx.com/images/common/back.gif
32-41行循环部分多了点~Func _Load1()
Local $hImage = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddBitmap($hImage, @ScriptDir & '\闲.bmp')
_GUIImageList_AddBitmap($hImage, @ScriptDir & '\忙.bmp')
_GUICtrlListView_SetImageList($ListView1, $hImage)
For $i = 1 To 10 Step 1
_GUICtrlListView_AddItem($ListView1, 'test' & $i, 0)
Next
EndFunc ;==>_Load1 回复 4# afan
哦 没注意看~ {:face (197):}感谢感谢,问题解决了~· 例子比较生动~~~~ 感谢分享! 学习了~~ 学习学习,新手报到
页:
[1]