Sign in to follow this  
Followers 0
NunoBorges

ListView Checkbox & spacebar

6 posts in this topic

Viva,

How can i :mellow: control the behavior of the spacebar in a listview checkbox.

With GUIRegisterMsg ($WM_NOTIFY, "WM_NOTIFY"), we can control almost everything, but the space bar?

A checkbox outside of a listview is very simple

thanks

Share this post


Link to post
Share on other sites



What, exactly, did you want to control about it? Just prevent CHECK/UNCHECK, or what?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Yes,

Just do something like msgbox when i check/uncheck.

I remenber that is something like keydown, but ...

Thanks

Share this post


Link to post
Share on other sites

I've found

On the "WM_NOTIFY"...

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $DriveView
    If Not IsHWnd($DriveView) Then $hWndListView = GUICtrlGetHandle($DriveView)
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_KEYDOWN
                    MsgBox(0, "", "$LVN_KEYDOWN")
...

Thanks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Changing the checkbox state changes the State Image Index (bits 12-15) of the State field in the LVITEM struct - which is used by the _GuiCtrlListView_GetItemChecked() function. You get LVN_ITEMCHANGING and LVN_ITEMCHANGED notifications, which give you a NMLISTVIEW struct where uNewState contains LVIS_STATEIMAGEMASK.

:mellow:

P.S. I don't think those notifications contain the actual new checkbox state, so when you get a WM_NOTIFY of LVN_ITEMCHANGED, and see LVIS_STATEIMAGEMASK in the uNewState field, then you still have to do _GuiCtrlListView_GetItemChecked() to get the check/uncheck state of the box. (Not tested though...)

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Actually, no.

Tested it this way:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $hListView, $iNM_Cnt = 0

GUICreate("ListView Get Item Checked State", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

; Add columns
_GUICtrlListView_AddColumn($hListView, "Column 1", 100)
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

; Check item 2
_GUICtrlListView_SetItemChecked($hListView, 1)
MsgBox(4160, "Information", "Item 2 Checked: " & _GUICtrlListView_GetItemChecked($hListView, 1))
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

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 $LVN_ITEMCHANGED ; An item has changed
                    $iNM_Cnt += 1
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    ConsoleWrite($iNM_Cnt & ":  $LVN_ITEMCHANGED" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param") & @LF)
                    ; No return value
                Case $LVN_ITEMCHANGING ; An item is changing
                    $iNM_Cnt += 1
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    ConsoleWrite($iNM_Cnt & ":  $LVN_ITEMCHANGING" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param") & @LF)
                    ; Return True ; prevent the change
                    Return False ; allow the change
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

If you watch the NewState and OldState fields you see the actual image index changing between 1 (unchecked) and 2 (checked). The bits are shifted up into bits 12-15, so it shows as 4096/8192.

So now we know.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0