Jump to content
Sign in to follow this  
momar33

$TVN_ITEMCHANGED value

Recommended Posts

momar33

Where can i find the hex value of TVN_ITEMCHANGED?

I need to updated a listview when a treeview is changed.

Share this post


Link to post
Share on other sites
momar33

Here is the code i was trying.

You may have the right constant, but i don't know how to use it.

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Switch $wParam
    Case $levelTV
        Switch $event
        Case $TVN_SELCHANGED
            msgbox(0,"","success")
        EndSwitch
    EndSwitch
endFunc  ;==>WM_Notify_Events

Share this post


Link to post
Share on other sites
momar33

Look here

Sorry, I forgot to mention that it is a CHECKBOX treeview.

I need to update the listview when any checkbox is changed.

Share this post


Link to post
Share on other sites
Zedna

Sorry, I forgot to mention that it is a CHECKBOX treeview.

I need to update the listview when any checkbox is changed.

HEY!

That's absolutely different.

So in this case I don't know how to do that.

Share this post


Link to post
Share on other sites
danielkza

HEY!

That's absolutely different.

So in this case I don't know how to do that.

Copied and pasted from my code,partially copied from somebody in the forums.If it's yours,sorry for the lack of credit:
Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    
    $hWndListView = $SkinsList
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                ; If the user right-clicked,prepare the context menu before showing it
                Case $NM_RCLICK, $NM_RDBLCLK
                    SkinMenuPrepare()
                    
                    ; If it's a left-click,detect if it was in the CheckBox or in the actual item
                Case $NM_CLICK, $NM_DBLCLK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")

                    If $iIndex <> -1 Then
                        Local $iX = DllStructGetData($tInfo, "X")
                        Local $iPart = 1
                        If _GUICtrlListView_GetView($hWndListView) = 1 Then $iPart = 2 ;for large icons view

                        ; Get the area of the actual item text
                        Local $aIconRect = _GUICtrlListView_GetItemRect($hWndListView, $iIndex, $iPart)
                        
                        ; If the click was to the left of the item retangle,it was in the checkbox
                        If $iX < $aIconRect[0] And $iX >= 5 Then
                            ; If the stopping flag was check,stop everything
                            ; This avoids infinite loop with _GUICtrlListVIew_SetItemChecked
                            If $SkinsListCheckStopFlag Then
                                $SkinsListCheckStopFlag = False
                            Else
                                ; Added checked item to the selected skins array
                                SkinsListCheck($iIndex, _GUICtrlListView_GetItemChecked($hWndListView, $iIndex) = 0)
                            EndIf
                            ; Don't execute standard actions
                            Return 0
                        Else
                            SkinsListClick()
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Share this post


Link to post
Share on other sites
Zedna

Copied and pasted from my code,partially copied from somebody in the forums.If it's yours,sorry for the lack of credit:

As far as I know you can check/uncheck also by {Space} on selected item.

This your code doesn't suppose this situation.

Share this post


Link to post
Share on other sites
rasim

momar33

Hi! This example showed how can processed mouse: left click, right click double click, and key pressed for getting a item check state. Just modify this example for your need.

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt("GuiOnEventMode", 1)

Global $Selected = 0

$GUI = GUICreate("Test")
GUISetOnEvent(-3, "Quit")

$label1 = GUICtrlCreateLabel('Selected = ', 10, 250)
$label2 = GUICtrlCreateLabel('', 70, 250)

$hListView = GUICtrlCreateListView("Column1", 20, 40, 200, 200, -1, $LVS_EX_CHECKBOXES + $WS_EX_OVERLAPPEDWINDOW)

Dim $avLVItems[5]

For $i = 0 To 4
    $avLVItems[$i] = GUICtrlCreateListViewItem("Item" & $i, $hListView)
Next

GUICtrlSetData($label2, $selected)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
    
    Sleep(100)
WEnd

Func Quit()
    Exit
EndFunc ;==>Quit

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $IdFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $IdFrom = DllStructGetData($tNMHDR, "IdFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $IdFrom
        Case $hListView
            Switch $iCode
                Case $LVN_KEYDOWN
                    Local $iIndex = _GUICtrlListView_GetSelectedIndices($hListView)
                    If $iIndex = "" Then Return $GUI_RUNDEFMSG
                    _GetItemChecked(_GUICtrlListView_GetItemChecked($hListView, $iIndex) = 0)
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")
                    
                    If $iIndex <> -1 Then
                        Local $iX = DllStructGetData($tInfo, "X")
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $iIndex)
                        If ($iX < $aRect[0]) And ($iX >= 5) Then _GetItemChecked(_GUICtrlListView_GetItemChecked($hListView, $iIndex) = 0)
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _GetItemChecked($sState)
    If $sState = True Then
        $Selected += 1
    Else
        $Selected -= 1
    EndIf
    GUICtrlSetData($label2, $Selected)
EndFunc
:D

Share this post


Link to post
Share on other sites
smashly

Sorry, I forgot to mention that it is a CHECKBOX treeview.

I need to update the listview when any checkbox is changed.

Hi, you can use the wm_notify function to handle both the treeview and listview events for when a state image is clicked.
#include <GUIConstants.au3>
#include <GuiListView.au3>
#Include <GuiTreeView.au3>

$Gui  = GUICreate("", 500, 300)
$hTreeView = GUICtrlCreateTreeView(5, 5, 220, 290, $TVS_CHECKBOXES)
GUICtrlCreateTreeViewItem("Item 1", $hTreeView)
GUICtrlCreateTreeViewItem("Item 2", $hTreeView)
$hListView = GUICtrlCreateListView("List Items", 230, 5, 265, 290, -1, $LVS_EX_CHECKBOXES)
GUICtrlCreateListViewItem("Item 1", $hListView)
GUICtrlCreateListViewItem("Item 2", $hListView)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    $hWndTreeView = $hTreeView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hTreeView) Then $hWndTreeView = GUICtrlGetHandle($hTreeView)
    $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
                    $aHit = _GUICtrlListView_HitTest($hWndListView)
                    If $aHit[4] Then
                        ConsoleWrite("ListView Item State Image Changed By NM_CLICK" & @LF)
                        ConsoleWrite("----------------------------------------------" & @LF)
                    EndIf
            EndSwitch
        Case $hWndTreeView
            Switch $iCode
                Case $NM_CLICK
                    Local $tPoint, $htvx
                    $tPoint = _WinAPI_GetMousePos(True, $hWndFrom)
                    $htvx =  _GUICtrlTreeView_HitTestEx($hWndTreeView, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
                    If BitAND(DllStructGetData($htvx, "Flags"), $TVHT_ONITEMSTATEICON) Then
                        ConsoleWrite("TreeView Item State Image Changed By NM_CLICK" & @LF)
                        ConsoleWrite("----------------------------------------------" & @LF)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Cheers

Share this post


Link to post
Share on other sites
rasim

smashly

Very good example with _WinAPI_GetMousePos(True, $hWndFrom)! Thank you! :D

Share this post


Link to post
Share on other sites
danielkza

If found a new solution,works with any kind of selection:click,keyboard,whatever. Tested in XP SP2

Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)
    
    $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_ITEMCHANGED
                    Local $tListView = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $hItem = DllStructGetData($tListView, "Item")
                    Local $Changed = DllStructGetData($tListView, "Changed")
                    
                    If $hItem <> - 1 And $Changed And BitAND($Changed, $LVIF_STATE) Then
                        Local $iOldState = BitShift(BitAND(DllStructGetData($tListView, "OldState"), $LVIS_STATEIMAGEMASK), 12)
                        Local $iNewState = BitShift(BitAND(DllStructGetData($tListView, "NewState"), $LVIS_STATEIMAGEMASK), 12)
                        
                        If $iOldState And $iNewState And ($iOldState <> $iNewState) Then
                            ;DoMyStuff($hWndListView,$hItem,$iNewState = 2)
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by danielkza

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  

×