#PRE_UseX64=n
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
;#include <WinAPITheme.au3>
#include <GuiListView.au3>
#include <WinAPISys.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <array.au3>
#include <Misc.au3>
Global $B_DESCENDING[3]
Global $hActLst
Global $bCtrlDown = False
Global $hEdit, $Item = -1, $SubItem = 0
Global $hEnter, $aAccelKeys[1][2] = [["{ENTER}", $hEnter]]
$iSelItem = -1
Local $hUser32 = DllOpen("user32.dll")
Local $ichked = 0
Local $tText = DllStructCreate("wchar Text[256]")
Local $GUI, $hImage
Local $iITEM_COUNT = 1000, $aShowdata[$iITEM_COUNT][4], $aShowdata2[$iITEM_COUNT][4], $aShowdata3[$iITEM_COUNT][4]
Local $sSomeString = ""
Local $hGUI, $hListView, $hListView2, $hListView3
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hGUI = GUICreate("ListView[" & UBound($aShowdata) & "]", 600, 605)
$hListView2 = GUICtrlCreateListView("$hListView2| | ", 300, 2, 295, 296, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_OWNERDATA), $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES + $LVS_EX_DOUBLEBUFFER) ;+ $LVS_EX_DOUBLEBUFFER
;~ _WinAPI_SetWindowTheme(GUICtrlGetHandle($hListView), "Explorer");
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 0, 110)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg($hListView2, $LVM_SETCOLUMNWIDTH, 2, 80)
GUICtrlSendMsg($hListView2, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0) ;
;===========創建並關聯圖像清單
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 15)
_GUICtrlListView_SetImageList($hListView, $hImage, 1) ;
_GUICtrlListView_SetImageList($hListView2, $hImage, 1) ;
GUISetState()
For $i = 0 To $iITEM_COUNT - 1
If $i = 18 Then
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView2, $LVM_REDRAWITEMS, 0, $i)
GUICtrlSendMsg($hListView3, $LVM_REDRAWITEMS, 0, $i)
EndIf
$aShowdata2[$i][0] = "2AA" & $i
$aShowdata2[$i][1] = "2BB" & $i
$aShowdata2[$i][2] = "2CC" & $i
$aShowdata2[$i][3] = 4096 ;
Next
While 1
$bCtrlDown = _IsPressed("11", $hUser32) ;
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd
GUIDelete()
DllClose($hUser32)
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $hListView2
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
;~ ConsoleWrite("$NM_CLICK" & @CRLF)
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $Index = DllStructGetData($tInfo, "Index"), _
$SubItem = DllStructGetData($tInfo, "SubItem"), _
$X = DllStructGetData($tInfo, "X")
If $X < 18 And (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hWndFrom), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then ;使用x坐标来判断是否在复选框上点击
If $aShowdata2[$Index][3] = 4096 Then
$aShowdata2[$Index][3] = 8192 ;4096未选中 8192选中
Else
$aShowdata2[$Index][3] = 4096 ;4096未选中 8192选中
EndIf
EndIf
Local $Info = DllStructCreate($tagNMLVDISPINFO, $ilParam)
DllStructSetData($Info, "State", $aShowdata2[$Index][3]) ;设置复选框状态
_GUICtrlListView_RedrawItems($hWndFrom, $Index, $Index) ;<====好像可以了。。。。复选框正常
Case -150, -177
_LVN_GETDISPINFO($iIDFrom, $ilParam, $aShowdata2)
Case $NM_CUSTOMDRAW
;~ ConsoleWrite("$NM_CUSTOMDRAW" & @CRLF)
Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT
; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations
Case $CDDS_ITEMPREPAINT
Return $CDRF_NOTIFYSUBITEMDRAW
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ;$CDDS_ITEMPREPAINT
; Before painting an item
Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
Switch $iItem
Case 5, 8, 11, 4
Switch DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")
Case 0
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x00CC00)
Case 1
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x008b00)
Case 2
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xe4CC00)
EndSwitch
Case 0 To 3
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xffCC00)
DllStructSetData($tNMLVCUSTOMDRAW, "clrText", 0xff00cc)
EndSwitch
If $iItem = $iSelItem Then
DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xADFF2F)
DllStructSetData($tNMLVCUSTOMDRAW, "clrText", 0xFFFFFF)
EndIf
EndSwitch
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
;~ Return $CDRF_NOTIFYSUBITEMDRAW
Case $LVN_ITEMCHANGED ; An item has changed
;~ ConsoleWrite("$LVN_ITEMCHANGED" & @CRLF)
Local $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $ilParam)
;~ _GUICtrlListView_RedrawItems($hWndFrom, $iSelItem, $iSelItem)
$iSelItem = DllStructGetData($tNMLISTVIEW, "Item")
_GUICtrlListView_SetItemSelected($hWndFrom, $iSelItem, False) ; Remove selected state
_GUICtrlListView_SetItemState($hListView2, $iSelItem, 0, $LVIS_FOCUSED) ; Remove focused state
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _LVN_GETDISPINFO($hlst, $ilParam, ByRef $aDataArray)
If Not IsArray($aDataArray) Then Return
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iIndex = Int(DllStructGetData($tInfo, "Item"))
$iSub = Int(DllStructGetData($tInfo, "SubItem"))
If BitAND(DllStructGetData($tInfo, "Mask"), $LVIF_IMAGE) And $iSub = 0 Then DllStructSetData($tInfo, "Image", 0)
If (BitAND(_GUICtrlListView_GetExtendedListViewStyle($hlst), $LVS_EX_CHECKBOXES) = $LVS_EX_CHECKBOXES) Then
DllStructSetData($tInfo, "Mask", BitOR($LVIF_STATE, DllStructGetData($tInfo, "Mask")))
DllStructSetData($tInfo, "StateMask", $LVIS_STATEIMAGEMASK)
DllStructSetData($tInfo, "State", $aDataArray[$iIndex][3])
EndIf
DllStructSetData($tText, "Text", $aDataArray[$iIndex][$iSub])
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText))
DllStructSetData($tInfo, "TextMax", StringLen($aDataArray[$iIndex][$iSub]))
EndFunc ;==>_LVN_GETDISPINFO
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR