这个给你参考参考。
#include <GUIConstants.au3>
;~ #include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GuiRebar.au3>
#include <GuiToolBar.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiMenu.au3>
#Include <GuiStatusBar.au3>
#include <Constants.au3>
Global $idMenuInsert = 1000
$Gui = GUICreate("测试", 320, 200)
$hListView = _GUICtrlListView_Create($GUI, "连接数(0)", 10, 10, 300, 180, -1, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($hListView, 0, 295)
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "添加连接", $idMenuInsert)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $iItemCount
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_RCLICK
If _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2) = $idMenuInsert Then
_GUICtrlListView_InsertItem($hListView, "www.autoitx.com")
$iItemCount = _GUICtrlListView_GetItemCount($hListView)
_GuiCtrlListView_SetColumn($hListView, 0, "连接数(" & $iItemCount & ")")
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc |