Champak Posted November 9, 2008 Share Posted November 9, 2008 (edited) I have a function that checks if the checkbox is checked/unchecked by ways of WM_Notify. The problem is WM_Notify will register if the cell around the checkbox is hit but the checkbox wont check/uncheck(like normal checkboxes when you click the text), so the function ends up failing sometimes. This example shows what I tried in order to compensate for not checking on the actual checkbox but instead the surrounding cell. Why? Just in case someone didn't hit exactly on the checkbox. It works, but then when you go to check/uncheck the actual checkbox, the box wont work. How can I fix or compensate for this? Be able to check/uncheck the checkbox by clicking on the actual checkbox or the cell containing the checkbox. expandcollapse popup#include <GUIListView.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $MediaGUI = GUICreate("",400,400,100,100) $hBurnGrab_ListView = _GUICtrlListView_Create ($MediaGUI, "#|1", 0, 0, 400, 300, $LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($hBurnGrab_ListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_TRACKSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_AddItem ($hBurnGrab_ListView, "") _GUICtrlListView_SetColumnWidth($hBurnGrab_ListView, 0, 50) _GUICtrlListView_SetColumnWidth($hBurnGrab_ListView, 1, 50) $Exit = GUICtrlCreateButton("Exit", 0, 320, 30, 30) GUICtrlSetOnEvent($Exit, "_Exit") GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Sleep(50) WEnd Func _Exit() Exit EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hBurnGrab_ListView Switch $iCode Case $NM_CLICK $tInfo = DllStructCreate($tagNMLVDISPINFO, $lParam) $aHit = _GUICtrlListView_SubItemHitTest ($hWndFrom) If ($aHit[0] <> -1) And ($aHit[1] >= 0) Then If DllStructGetData($tInfo, "Item") = 0 Then If _GUICtrlListView_GetItemChecked($hBurnGrab_ListView, $aHit[0]) Then ConsoleWrite("+ Checked " & $aHit[0] & @CRLF) _GUICtrlListView_SetItemChecked($hBurnGrab_ListView, $aHit[0], False);attempted compensation ;$Checked = True ElseIf Not _GUICtrlListView_GetItemChecked($hBurnGrab_ListView, $aHit[0]) Then ConsoleWrite("+ Unchecked " & $aHit[0] & @CRLF) _GUICtrlListView_SetItemChecked($hBurnGrab_ListView, $aHit[0], True);attempted compensation ;$Checked = False EndIf EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited November 9, 2008 by Champak Link to comment Share on other sites More sharing options...
smashly Posted November 9, 2008 Share Posted November 9, 2008 (edited) Without altering your code to muchexpandcollapse popup#include <GUIListView.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $MediaGUI = GUICreate("",400,400,100,100) $hBurnGrab_ListView = _GUICtrlListView_Create ($MediaGUI, "#|1", 0, 0, 400, 300, $LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($hBurnGrab_ListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_TRACKSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_AddItem ($hBurnGrab_ListView, "") _GUICtrlListView_SetColumnWidth($hBurnGrab_ListView, 0, 50) _GUICtrlListView_SetColumnWidth($hBurnGrab_ListView, 1, 50) $Exit = GUICtrlCreateButton("Exit", 0, 320, 30, 30) GUICtrlSetOnEvent($Exit, "_Exit") GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Sleep(50) WEnd Func _Exit() Exit EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hBurnGrab_ListView Switch $iCode Case $NM_CLICK Local $aHit1 = _GUICtrlListView_HitTest($hWndFrom) If $aHit1[4] Then Return $GUI_RUNDEFMSG If $aHit1[3] Then If _GUICtrlListView_GetItemChecked($hWndFrom, $aHit1[0]) Then _GUICtrlListView_SetItemChecked($hWndFrom, $aHit1[0], False) Else _GUICtrlListView_SetItemChecked($hWndFrom, $aHit1[0], True) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited November 9, 2008 by smashly Link to comment Share on other sites More sharing options...
Champak Posted November 10, 2008 Author Share Posted November 10, 2008 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now