Войти

Показать полную графическую версию : [решено] Как узнать изменено ли значение checkbox


malev
20-10-2009, 11:32
Как узнать менялось ли значение checkbox у строки из ListView, это не помогает - "If BitAND(GUICtrlRead($iCtrlID), $GUI_CHECKED) Then ..."

FlatX007
20-10-2009, 12:04
Может я не правильно понял :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $sIndex[2] = ["Checkbox1", "Checkbox2"]

$nForm = GUICreate("", 196, 92)
$Checkbox1 = GUICtrlCreateCheckbox($sIndex[0], 8, 8, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox($sIndex[1], 8, 32, 97, 17)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWndGUI, $MsgID, $WParam, $LParam)
Local $iIDFrom = BitAND($wParam, 0xFFFF)
Local $iCode = BitShift($wParam, 16)
Dim $aRead[2] = [GUICtrlRead($iIDFrom), GUICtrlRead($iIDFrom, 1)]

For $i = 0 To UBound($sIndex) - 1
If $aRead[1] = $sIndex[$i] Then
MsgBox(0, Default, "Изменено значение чекбокса - " & $aRead[1])
ExitLoop
EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc

Creat0R
20-10-2009, 14:11
Может я не правильно понял »
Неа :) Автор же пишет про checkbox в ListView. И в случае с твоим примером не нужен WM_COMMAND, оно проверяется в цикле обычно.

Как узнать менялось ли значение checkbox у строки из ListView »
Я как то тоже был озадачен этим вопросом, вот пример:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GuiListView.au3>
;

$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("ListView Item Сhecked")

$hListView = GUICtrlCreateListView (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateListView.htm)("Column 1|Column 2", 10, 10, 380, 360, -1, $LVS_EX_CHECKBOXES + $WS_EX_DLGMODALFRAME)

_GUICtrlListView_RegisterSortCallBack($hListView)

For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 10
GUICtrlCreateListViewItem (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateListViewItem.htm)("Item " & $i & "|SubItem " & $i, $hListView)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)

$Status_Label = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)("", 10, 385, 380, 15, $SS_SUNKEN)

GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
GUIRegisterMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_NOTIFY, "WM_NOTIFY")

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) ItemChecked_Proc($iItem, $bState, $iID)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Status_Label, "<" & $iItem & "> is checked = " & $bState & ", CtrlID = " & $iID)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
$hWndListView = $hListView
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($hListView) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $hWndListView = GUICtrlGetHandle (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlGetHandle.htm)($hListView)

$tNMHDR = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMHDR, $lParam)
$hWndFrom = HWnd (http://www.autoitscript.com/autoit3/docs/functions/HWnd.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "IDFrom")
$iCode = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tNMHDR, "Code")

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $hWndFrom
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hWndListView
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iCode
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $LVN_COLUMNCLICK ; A column was clicked
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tInfo = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMLISTVIEW, $lParam)

; Kick off the sort callback
_GUICtrlListView_SortItems($hWndFrom, DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tInfo, "SubItem"))
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $NM_CLICK, $NM_DBLCLK, $NM_RCLICK
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tInfo = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)($tagNMITEMACTIVATE, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iIndex = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tInfo, "Index")

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iIndex <> -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iX = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tInfo, "X")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iPart = 1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) _GUICtrlListView_GetView($hListView) = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iPart = 2 ;for large icons view

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aIconRect = _GUICtrlListView_GetItemRect($hListView, $iIndex, $iPart)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iX < $aIconRect[0] And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $iX >= 5 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$iOld_Sel_Index = _GUICtrlListView_GetSelectedIndices($hListView)
_GUICtrlListView_SetItemSelected($hListView, $iIndex)

$iID = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($iIDFrom)

ControlListView (http://www.autoitscript.com/autoit3/docs/functions/ControlListView.htm)($hWnd, "", $iIDFrom, "SelectClear")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iOld_Sel_Index <> "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) _GUICtrlListView_SetItemSelected($hListView, Number (http://www.autoitscript.com/autoit3/docs/functions/Number.htm)($iOld_Sel_Index))

ItemChecked_Proc(_GUICtrlListView_GetItemText($hListView, $iIndex), _
(_GUICtrlListView_GetItemChecked($hListView, $iIndex) = 0), $iID)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) 0
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

malev
20-10-2009, 16:06
Вот это код, действительно работает, еще бы как узнать ControlID чекнутого элемента, индекс не подойдет так как я сортирую список

Creat0R
21-10-2009, 06:51
индекс не подойдет так как я сортирую список »
Ну а зачем ID для сортировки? Я поправил свой пример, он теперь включает и сортировку :)

как узнать ControlID чекнутого элемента »
И это добавил в свой пример.

malev
21-10-2009, 13:40
Конечно ID не нужен для сортировки просто мне нужно записать check строки в файл, а при сортировке все индекса меняются кто был первым может стать последним поэтому и идентифицирую запись по ID. Можно конечно еще поле добавить порядковый номер...Считаю тему решенной. Спасибо.




© OSzone.net 2001-2012