Hello guys,
Maybe a stupid problem but i can't solve it. A reproducer script:
AutoIt
#include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $fItem = -1 $Form = GUICreate("Form1", 266, 233, 204, 144) $ListView1 = GUICtrlCreateListView("AAA", 8, 8, 250, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) $hListView = GUICtrlGetHandle($ListView1) $ListView1_0 = GUICtrlCreateListViewItem("7.03_MB", $ListView1) $ListView1_1 = GUICtrlCreateListViewItem("317_byte", $ListView1) $ListView1_2 = GUICtrlCreateListViewItem("113.30_KB", $ListView1) $ListView1_3 = GUICtrlCreateListViewItem("36.61_KB", $ListView1) $ListView1_4 = GUICtrlCreateListViewItem("5.97_MB", $ListView1) $Label = GUICtrlCreateLabel("10000000", 8, 168) _GUICtrlListView_SetItemChecked($ListView1, 0) _GUICtrlListView_SetItemChecked($ListView1, 1) _GUICtrlListView_SetItemChecked($ListView1, 2) _GUICtrlListView_SetItemChecked($ListView1, 3) _GUICtrlListView_SetItemChecked($ListView1, 4) $a = _Convert("7.03_MB") $b = _Convert("317_BYTE") $c = _Convert("113.30_KB") $d = _Convert("36.61_KB") $e = _Convert("5.97_MB") GUICtrlSetData($Label, _Final($a + $b + $c + $d + $e)) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If $fItem <> -1 Then _Func($fItem) $fItem = -1 EndIf ;==> WEnd Func _Func($fItem) $sTest = _GUICtrlListView_GetItemChecked($ListView1, $fItem) If $sTest = False Then $y = _Convert(_GUICtrlListView_GetItemText($ListView1, $fItem)) $z = _Convert(GUICtrlRead($Label)) GUICtrlSetData($Label, _Final($z-$y)) Else $y = _Convert(_GUICtrlListView_GetItemText($ListView1, $fItem)) $z = _Convert(GUICtrlRead($Label)) GUICtrlSetData($Label, _Final($z+$y)) EndIf EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $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 $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iItem = DllStructGetData($tInfo, "Index") $fItem = $iItem EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _Convert($sNumber) Switch StringRight($sNumber, 2) Case "GB" Return StringRegExpReplace(StringTrimRight($sNumber, 3) * 1073741824, "(\.\d{2}).*", "$1") Case "MB" Return StringRegExpReplace(StringTrimRight($sNumber, 3) * 1048576, "(\.\d{2}).*", "$1") Case "KB" Return StringRegExpReplace(StringTrimRight($sNumber, 3) * 1024, "(\.\d{2}).*", "$1") Case Else Return StringRegExpReplace(StringTrimRight($sNumber, 5), "(\.\d{2}).*", "$1") EndSwitch EndFunc ;==>_Convert Func _Final($iSize) Select Case $iSize >= 1073741824 Return StringRegExpReplace($iSize / 1073741824, "(\.\d{2}).*", "$1") & "_GB" Case $iSize >= 1048576 Return StringRegExpReplace($iSize / 1048576, "(\.\d{2}).*", "$1") & "_MB" Case $iSize >= 1024 Return StringRegExpReplace($iSize / 1024, "(\.\d{2}).*", "$1") & "_KB" Case $iSize >= 0 Return StringRegExpReplace($iSize, "(\.\d{2}).*", "$1") & "_BYTE" EndSelect EndFunc ;==>_Final
Yes, is not "perfect" ( like the click on the checkbox and not on the text!) but it just reproduce the problem. I have a list of size, MB-GB-KB-BYTE i want to add-subtract that value in a label of the total size...easy? Seems not
Example, start it and uncheck the 5.97_MB, the label become 7.17_MB, if i click again 5.97_MB the label come back to 13.14_MB, until here is working
Again, lauch it and uncheck the 113.30_KB...the label become 13.02_MB, click it again and then become 13.13_MB, unclick 13.01_MB, click 13.12_MB and so on..always the wrong value and still decreasing
What are my (many) mistakes? Thanks