修改一下,你试试:
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
Opt("GuiOnEventMode", 1)
Global Enum $idOpen = 1000
Global $idGui = GUICreate("", 420, 500)
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
Global $idListview = GUICtrlCreateListView("", 10, 50, 400, 156, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))
GUICtrlSetBkColor(-1, 0xFFFBF0)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_INFOTIP, $LVS_EX_SUBITEMIMAGES)
_GUICtrlListView_SetExtendedListViewStyle($idListview, $iStyle) ;设置扩展样式
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 7)
_GUICtrlListView_AddColumn($idListview, "值", 60)
_GUICtrlListView_AddColumn($idListview, "域", 230)
Global $hListview = GUICtrlGetHandle($idListview)
GUISetState()
GUISetOnEvent(-3, "_Exit")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
Global $aArrayList[5][2] = [["状态", "证书有效"], ["序列号", "ABCDEFGH"], ["持有者", "DDDDDDDDD"], ["指纹", "GGGGGGGGGGG"], ["有效期", "20220406"]]
_GUICtrlListView_AddArray($idListview, $aArrayList)
;_Key_GuiSetData()
While 1
Sleep(10)
WEnd
Func _CopyItems()
;MsgBox(0, 0, "右键菜单测试。如果把数组$aArrayList清空,则不会弹出右键菜单!", "", $idGui)
$index = _GUICtrlListView_GetSelectedIndices($idListview)
$index1 = $index + 1
Local $cont = _GUICtrlListView_GetItemCount($hListview)
$h1 = 0
For $id = 0 To $cont - 1
$str = _GUICtrlListView_GetItemTextArray($hListview, $index)
$h1 = $str[1]
$h2 = $str[2]
$hA2 = $h1 & " , " & $h2
Next
MsgBox(0, "复制 " & $index1 & " 行", $hA2)
EndFunc ;==>_CopyItems
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $iwParam
Case $idOpen
_CopyItems()
EndSwitch
EndFunc ;==>WM_COMMAND
Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
Local $gUK_Text
Local $iCols = _GUICtrlListView_GetColumnCount($idListview) ;检索列表视图列数
Local $iRows = _GUICtrlListView_GetItemCount($idListview) ;检索列表视图行数
For $i = 0 To $iRows - 1
For $j = 0 To $iCols - 1
If _GUICtrlListView_GetItemText($idListview, $i, $j) = "证书有效" Then
$gUK_Text = "证书有效"
ExitLoop
EndIf
Next
Next
Switch $iwParam
Case $hListview ;必须是句柄才行,不能是是控件的ID
$index = _GUICtrlListView_GetSelectedIndices($hListview)
If $index <> "" Then
Local $hMenu = _GUICtrlMenu_CreatePopup() ;创建下拉菜单, 子菜单或快捷菜单.
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "复制", $idOpen) ;插入一个新菜单项到指定位置.(使用参数)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd) ;在指定位置显示一个快捷菜单
_GUICtrlMenu_DestroyMenu($hMenu) ;销毁指定菜单, 并释放菜单占用的内存
Return True
Else
MsgBox(0, "右键点击", "你点击的是空格")
EndIf
EndSwitch
EndFunc ;==>WM_CONTEXTMENU1
Func _Exit()
Exit
EndFunc ;==>_Exit
|