<p>#NoTrayIcon
#RequireAdmin
#PRE_UseX64 = n
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
Opt("GuiOnEventMode", 1)
Global Enum $idOpen = 1000 ;Listview右键</p><p>Global $idGui = GUICreate("", 420, 500)</p><p>DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
Global $idListview = GUICtrlCreateListView("", 10, 50, 400, 136, 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, "域", 130)
Global $hListview = GUICtrlGetHandle($idListview)
GUISetState()
GUISetOnEvent(-3, "_Exit")</p><p>GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;$WM_COMMAND:0x0111,当用户选择一条菜单命令项或当某个控件发送一条消息给它的父窗口
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") ;$WM_CONTEXTMENU:0x007B,当用户某个窗口中点击了一下右键就发送此消息给这个窗口</p><p>Global $aArrayList[5][2] = [["状态", "证书有效"], ["序列号", "ABCDEFGH"], ["持有者", "DDDDDDDDD"], ["指纹", "GGGGGGGGGGG"], ["有效期", "20220406"]]
_GUICtrlListView_AddArray($idListview, $aArrayList)</p><p>While 1
Sleep(10)
WEnd </p><p>Func _CopyItems()
MsgBox(0, 0, "右键菜单测试。如果把数组$aArrayList清空,则不会弹出右键菜单!", "", $idGui)
EndFunc</p><p>Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;$WM_COMMAND:0x0111,当用户选择一条菜单命令项或当某个控件发送一条消息给它的父窗口
Switch $iwParam
Case $idOpen
_CopyItems()
EndSwitch
EndFunc ;==>WM_COMMAND</p><p>Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) ;$WM_CONTEXTMENU:0x007B,当用户某个窗口中点击了一下右键就发送此消息给这个窗口
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
If $gUK_Text <> "" Then
Local $hMenu = _GUICtrlMenu_CreatePopup() ;创建下拉菜单, 子菜单或快捷菜单.
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "复制", $idOpen) ;插入一个新菜单项到指定位置.(使用参数)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd) ;在指定位置显示一个快捷菜单
_GUICtrlMenu_DestroyMenu($hMenu) ;销毁指定菜单, 并释放菜单占用的内存
Return True
EndIf
EndSwitch
EndFunc ;==>WM_CONTEXTMENU</p><p>Func _Exit()
Exit
EndFunc
</p>