本帖最后由 xyhqqaa 于 2018-11-27 13:54 编辑
求助大佬们,想法其实是点击图标后运行对应的操作。目前初步的想法,是获取图标对应的文本。但是操作过程中发现,使用_GUICtrlListView_GetSelectedIndices($mainListView)可以正常获取图标索引,
_GUICtrlListView_GetItemText($mainListView, 3),使用这个可以获取指定索引的文本。
但是将两者嵌套, _GUICtrlListView_GetItemText($mainListView, _GUICtrlListView_GetSelectedIndices($mainListView))却无法获取文本。。。。
是思路错了。还是参数用错了。。。求大佬指教
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
;_loginform() ;登录
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$Form = GUICreate("Form12", 683, 590, 292, 151)
$MenuItem1 = GUICtrlCreateMenu("MenuItem1")
$MenuItem6 = GUICtrlCreateMenuItem("MenuItem6", $MenuItem1)
$MenuItem7 = GUICtrlCreateMenuItem("MenuItem7", $MenuItem1)
$MenuItem8 = GUICtrlCreateMenuItem("MenuItem8", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("MenuItem2")
$MenuItem3 = GUICtrlCreateMenu("MenuItem3")
$MenuItem5 = GUICtrlCreateMenu("MenuItem5")
$MenuItem4 = GUICtrlCreateMenu("MenuItem4")
$TreeView1 = GUICtrlCreateTreeView(0, 0, 161, 545)
$TreeView1_1 = GUICtrlCreateTreeViewItem("1", $TreeView1)
$TreeView1_11 = GUICtrlCreateTreeViewItem("测试", $TreeView1_1)
$TreeView1_12 = GUICtrlCreateTreeViewItem("测试", $TreeView1_1)
$TreeView1_13 = GUICtrlCreateTreeViewItem("测试", $TreeView1_1)
$TreeView1_14 = GUICtrlCreateTreeViewItem("测试", $TreeView1_1)
GUICtrlSetState($TreeView1_1, $GUI_EXPAND) ;默认展开
$TreeView1_2 = GUICtrlCreateTreeViewItem("2", $TreeView1)
$TreeView1_21 = GUICtrlCreateTreeViewItem("测试", $TreeView1_2)
$TreeView1_22 = GUICtrlCreateTreeViewItem("测试", $TreeView1_2)
$TreeView1_23 = GUICtrlCreateTreeViewItem("测试", $TreeView1_2)
$TreeView1_24 = GUICtrlCreateTreeViewItem("测试", $TreeView1_2)
GUICtrlSetState($TreeView1_2, $GUI_EXPAND) ;默认展开
$TreeView1_3 = GUICtrlCreateTreeViewItem("3", $TreeView1)
$TreeView1_31 = GUICtrlCreateTreeViewItem("测试", $TreeView1_3)
$TreeView1_32 = GUICtrlCreateTreeViewItem("测试", $TreeView1_3)
$TreeView1_33 = GUICtrlCreateTreeViewItem("测试", $TreeView1_3)
$TreeView1_34 = GUICtrlCreateTreeViewItem("测试", $TreeView1_3)
GUICtrlSetState($TreeView1_3, $GUI_EXPAND) ;默认展开
$TreeView1_4 = GUICtrlCreateTreeViewItem("设置", $TreeView1)
$TreeView1_41 = GUICtrlCreateTreeViewItem("界面设置", $TreeView1_4)
$TreeView1_42 = GUICtrlCreateTreeViewItem("账户管理", $TreeView1_4)
$TreeView1_43 = GUICtrlCreateTreeViewItem("测试", $TreeView1_4)
$TreeView1_44 = GUICtrlCreateTreeViewItem("关于", $TreeView1_4)
GUICtrlSetState($TreeView1_4, $GUI_EXPAND) ;默认展开
_GUICtrlTreeView_SetIcon($TreeView1, $TreeView1_4, "shell32.dll", 3)
$mainListView = GUICtrlCreateListView("", 168, 0, 514, 550)
GUICtrlSetStyle($mainListView, $WS_BORDER + $LVS_ICON) ;图标视图模式
$mainImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 0, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 1, True)
_GUIImageList_AddIcon($mainImage, "icon.dll", 2, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 4, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 5, True)
_GUICtrlListView_SetImageList($mainListView, $mainImage, 0)
_GUICtrlListView_AddItem($mainListView, "测试1", 0)
_GUICtrlListView_AddItem($mainListView, "测试2", 1)
_GUICtrlListView_AddItem($mainListView, "测试3", 2)
_GUICtrlListView_AddItem($mainListView, "测试4", 3)
_GUICtrlListView_AddItem($mainListView, "测试5", 4)
$StatusBar1 = _GUICtrlStatusBar_Create($Form)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $TreeView1_1
Case $TreeView1_11
_GUICtrlListView_DeleteAllItems($mainListView)
Case $TreeView1_41 ;界面设置
_GUICtrlListView_DeleteAllItems($mainListView)
Visualsettings()
EndSwitch
WEnd
Func Visualsettings() ;界面设置
$mainImage = _GUIImageList_Create(48, 48, 5, 3, 6)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 1, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 2, True)
_GUIImageList_AddIcon($mainImage, "icon.dll", 3, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 4, True)
_GUIImageList_AddIcon($mainImage, 'icon.dll', 5, True)
_GUICtrlListView_SetImageList($mainListView, $mainImage, 0)
_GUICtrlListView_AddItem($mainListView, "1", 0)
_GUICtrlListView_AddItem($mainListView, "2", 1)
_GUICtrlListView_AddItem($mainListView, "3", 2)
_GUICtrlListView_AddItem($mainListView, "4", 3)
_GUICtrlListView_AddItem($mainListView, "5", 4)
;_GUICtrlListView_SetItemPosition($ListView1, 0, 50, 100)
;_GUICtrlListView_SetItemPosition($ListView1, 1, 140, 100)
;_GUICtrlListView_SetItemPosition($ListView1, 2, 230, 100)
;_GUICtrlListView_SetItemPosition($ListView1, 3, 320, 100)
;_GUICtrlListView_SetItemPosition($ListView1, 4, 410, 100)
;_GUICtrlListView_SetItemPosition($ListView1, 5, 50, 200)
EndFunc ;==>Visualsettings
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $iCode, $hWndFrom, $tNMTOOLBAR, $iItem
Local $hListView = GUICtrlGetHandle($mainListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $ilParam)
$iItem = DllStructGetData($tNMTOOLBAR, "iItem")
Switch $hWndFrom
Case $hListView ;这里改成你的listview的ID
Switch $iCode
Case $NM_DBLCLK ;双击
$Index = _GUICtrlListView_GetSelectedIndices($mainListView)
If Not StringLen($Index) Then ; 判定是否选定listview
MsgBox(0, "", "未选定")
Else
MsgBox("", "", _GUICtrlListView_GetSelectedIndices($mainListView)) ;获取索引
MsgBox("", "", _GUICtrlListView_GetItemText($mainListView, 3)) ;获取项目文本
MsgBox("", "", _GUICtrlListView_GetItemText($mainListView, _GUICtrlListView_GetSelectedIndices($mainListView))) ;获取项目文本
EndIf
Case $NM_RCLICK ; 右擊
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|