本帖最后由 kk_lee69 于 2016-10-15 22:56 编辑
回复 14# chzj589
弄好了 你看一下吧 用上面的範例 改的 你應該 可以理解 也感謝 tubaba 兄 的舉例 讓我了解的 前面一直搞不懂的邏輯
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
Global $hListItem[2]
Global $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aHit, $hImage
Global $iColor, $iColorBk, $fChildGui = False
Local $path, $aFileList, $aNewList[1][2]
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
Local $iI, $iTimer, $idListview
$Main_GUI = GUICreate("Test Management v1.0", 720, 300)
$idListview = GUICtrlCreateListView("", 15, 15, 550, 268)
$hListView = GUICtrlGetHandle($idListview)
$idComboBox = GUICtrlCreateCombo("", 600, 246, 90, 30)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlListView_AddColumn($idListview, "Tester", 100)
_GUICtrlListView_AddColumn($idListview, "Test Item", 100)
_GUICtrlListView_AddColumn($idListview, "BMC IP", 100)
_GUICtrlListView_AddColumn($idListview, "Count", 60)
_GUICtrlListView_AddColumn($idListview, "Last Record Time", 150)
ReDim $aNewList[3][5]
Local $sComboTxt = "所有"
$aNewList[0][0]="A"
$aNewList[0][1]="A1"
$aNewList[0][2]="A29"
$aNewList[0][3]="B1"
$aNewList[0][4]="C1"
$aNewList[1][0]="K"
$aNewList[1][1]="DA1"
$aNewList[1][2]="AKKK29"
$aNewList[1][3]="BXX1"
$aNewList[1][4]="Cee1"
$aNewList[2][0]="AAA"
$aNewList[2][1]="A1DDD"
$aNewList[2][2]="A29"
$aNewList[2][3]="B1"
$aNewList[2][4]="C1"
GUICtrlSetData($idComboBox, $sComboTxt, "所有")
_GUICtrlListView_AddArray($idListview, $aNewList)
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $idComboBox
$sComboRead = GUICtrlRead($idComboBox)
If $sComboRead == "所有" Then
_GUICtrlListView_DeleteAllItems($idListview)
_GUICtrlListView_AddArray($idListview, $aNewList)
Else
_GUICtrlListView_DeleteAllItems($idListview)
For $i = 0 To UBound($aNewList) - 1
If $aNewList[$i][1] == $sComboRead Then
GUICtrlCreateListViewItem($aNewList[$i][0] & "|" & $aNewList[$i][1] & "|" & $aNewList[$i][2] & "|" & $aNewList[$i][3] & "|" & $aNewList[$i][4], $idListview)
EndIf
Next
EndIf
EndSwitch
WEnd
;-----------------------------------------------------------------------------------------------------------
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_ENDSCROLL
$tNMHDR = DllStructCreate("hwnd hWnd;uint cID;int code", $ilParam)
$hLV = HWnd(DllStructGetData($tNMHDR, "hWnd"))
_WinAPI_InvalidateRect($hLV)
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$aHit = _GUICtrlListView_SubItemHitTest($hListView)
If $aHit[0] < 0 Then Return $GUI_RUNDEFMSG
Switch $aHit[1]
Case 7
$fChildGui = True
Child_GUI($aHit[0])
EndSwitch
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $sComboRead = GUICtrlRead($idComboBox)
If $iSubItem Then
IF _GUICtrlListView_GetItemText($hWndListView,$iItem,$iSubItem)="A29" Then
$iColor = 0x0000FF
$iColorBk = 0xC0C0C0
Else
$iColor = 0x000000
$iColorBk = 0xFFFFFF
EndIf
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", $iColorBk)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
;-----------------------------------------------------------------------------------------------------------
Func Child_GUI($y)
; GUISetState(@SW_LOCK, $Main_GUI) ; uncommented changes behaviour
$APPTSTAT_GUI = GUICreate("", 230, 180, 560, 140)
GUISetState(@SW_SHOW, $APPTSTAT_GUI)
While 1
$msg2 = GUIGetMsg()
Switch $msg2
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
Sleep(50) ; why is this necessary? otherwise crashes
WEnd
GUIDelete($APPTSTAT_GUI)
GUISetState(@SW_RESTORE, $Main_GUI)
; GUISetState(@SW_UNLOCK, $Main_GUI); uncommented changes behaviour
EndFunc ;==>Child_GUI
|