[已解决]ListView如何msgbox一個一個帶出所有的$hListView
本帖最后由 ipmitool 于 2016-12-5 15:44 编辑請問下面範例有四個
GUICtrlCreateListViewItem("OSInstallation", $hListView)
GUICtrlCreateListViewItem("1k-AC Power Cycle", $hListView)
GUICtrlCreateListViewItem("1k-WarmBoot", $hListView)
GUICtrlCreateListViewItem("ToolpackageTest", $hListView)
我如何點下execute的時候就 分別 msgbox出這四個hlistview#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <MsgBoxConstants.au3>
Global $GUI, $hListView, $Up, $Down, $msg
$GUI = GUICreate("UP/Down ListView", 300, 340)
$hListView = GUICtrlCreateListView ("Test Case ", 10, 10, 220, 220)
GUICtrlCreateListViewItem("OSInstallation", $hListView)
GUICtrlCreateListViewItem("1k-AC Power Cycle", $hListView)
GUICtrlCreateListViewItem("1k-WarmBoot", $hListView)
GUICtrlCreateListViewItem("ToolpackageTest", $hListView)
Global $hCMenu = GUICtrlCreateContextMenu($hListView)
Global $hCMenuText1 = GUICtrlCreateMenuItem("Delete", $hCMenu)
Global $hCMenuText2 = GUICtrlCreateMenuItem("Show", $hCMenu)
Global $sItemText ;this will store the text of the last right-clicked item.
$Up = GUICtrlCreateButton("Up", 240, 30, 40, 20)
$Down = GUICtrlCreateButton("Down", 240, 60, 40, 20)
$Execute = GUICtrlCreateButton("Execute", 100, 240, 70, 30)
While 1
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $GUI)
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Up
If UD($hListView, 0) = -1 Then MsgBox(64, "Top", "Item is at the top of the ListView", 1)
Case $Down
If UD($hListView, 1) = -1 Then MsgBox(64, "Bottom", "Item is at the bottom of the ListView", 1)
case $Execute
MsgBox(0, "listview item", "...", 1)
case $hCMenuText1 ;delete
_GUICtrlListView_DeleteItemsSelected($hListView)
case $hCMenuText2 ;show
_ShowText()
EndSwitch
Wend
Func UD($iCID, $iFlag)
Local $iCnt, $sCur,$iCur, $sNxt, $iNew = -1
$iCur = _GUICtrlListView_GetNextItem($iCID)
$sCur = _GUICtrlListView_GetItemText($iCID, $iCur)
$iCnt = _GUICtrlListView_GetItemCount($iCID)
If $iFlag And $iCur < ($iCnt - 1) Then
$iNew = $iCur + 1
ElseIf Not $iFlag And $iCur > 0 Then
$iNew = $iCur - 1
EndIf
If $iNew = -1 Then Return $iNew
$sNxt = _GUICtrlListView_GetItemText($iCID, $iNew)
_GUICtrlListView_SetItemText($iCID, $iNew, $sCur)
_GUICtrlListView_SetItemText($iCID, $iCur, $sNxt)
_GUICtrlListView_SetItemSelected($iCID, $iNew, 1)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
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
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$SubItem = DllStructGetData($tInfo, "SubItem")
$sItemText =_GUICtrlListView_GetItemText($hWndListView, $Index, $SubItem)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _ShowText()
If $sItemText <> "" Then MsgBox(0,"Name", $sItemText)
EndFunc 回复 1# ipmitool
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <MsgBoxConstants.au3>
Global $GUI, $hListView, $Up, $Down, $msg
$GUI = GUICreate("UP/Down ListView", 300, 340)
$hListView = GUICtrlCreateListView ("Test Case ", 10, 10, 220, 220)
GUICtrlCreateListViewItem("OSInstallation", $hListView)
GUICtrlCreateListViewItem("1k-AC Power Cycle", $hListView)
GUICtrlCreateListViewItem("1k-WarmBoot", $hListView)
GUICtrlCreateListViewItem("ToolpackageTest", $hListView)
Global $hCMenu = GUICtrlCreateContextMenu($hListView)
Global $hCMenuText1 = GUICtrlCreateMenuItem("Delete", $hCMenu)
Global $hCMenuText2 = GUICtrlCreateMenuItem("Show", $hCMenu)
Global $sItemText ;this will store the text of the last right-clicked item.
$Up = GUICtrlCreateButton("Up", 240, 30, 40, 20)
$Down = GUICtrlCreateButton("Down", 240, 60, 40, 20)
$Execute = GUICtrlCreateButton("Execute", 100, 240, 70, 30)
While 1
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $GUI)
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Up
If UD($hListView, 0) = -1 Then MsgBox(64, "Top", "Item is at the top of the ListView", 1)
Case $Down
If UD($hListView, 1) = -1 Then MsgBox(64, "Bottom", "Item is at the bottom of the ListView", 1)
case $Execute
;$ColumnCount=_GUICtrlListView_GetColumnCount($hListView)
$ItemCount=_GUICtrlListView_GetItemCount($hListView)
FOR $i=0 to $ItemCount-1
;FOR $j=0 to $ColumnCount-1
MsgBox(0, "listview item", _GUICtrlListView_GetItemTextString($hListView,$i), 1)
;Next
Next
case $hCMenuText1 ;delete
_GUICtrlListView_DeleteItemsSelected($hListView)
case $hCMenuText2 ;show
_ShowText()
EndSwitch
Wend
Func UD($iCID, $iFlag)
Local $iCnt, $sCur,$iCur, $sNxt, $iNew = -1
$iCur = _GUICtrlListView_GetNextItem($iCID)
$sCur = _GUICtrlListView_GetItemText($iCID, $iCur)
$iCnt = _GUICtrlListView_GetItemCount($iCID)
If $iFlag And $iCur < ($iCnt - 1) Then
$iNew = $iCur + 1
ElseIf Not $iFlag And $iCur > 0 Then
$iNew = $iCur - 1
EndIf
If $iNew = -1 Then Return $iNew
$sNxt = _GUICtrlListView_GetItemText($iCID, $iNew)
_GUICtrlListView_SetItemText($iCID, $iNew, $sCur)
_GUICtrlListView_SetItemText($iCID, $iCur, $sNxt)
_GUICtrlListView_SetItemSelected($iCID, $iNew, 1)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
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
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$SubItem = DllStructGetData($tInfo, "SubItem")
$sItemText =_GUICtrlListView_GetItemText($hWndListView, $Index, $SubItem)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _ShowText()
If $sItemText <> "" Then MsgBox(0,"Name", $sItemText)
EndFunc 回复 2# kk_lee69
真不愧是馬蓋仙, 我上個廁所的時間你就寫好了...好強啊!
页:
[1]