Jump to content

Need Help Blocking $LVN_ITEMCHANGING on ListView


Recommended Posts

Ok here's the end result I'm looking for

1) A listview that allows no user interaction (ie., selecting or dragging items) except for scrolling

2) A listview that allows me to update state images from within my script.

Using some info I found in a few posts I have satisfied part 1, but I can't update the listview from within my script.

Is there a parameter I can look at in WM_NOTIFY that will tell me whether the change is internal or external? Or something to that effect?

This way I can allow programatic changes to succeed.

Thanks,

Kenny

#include <StructureConstants.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Global $GUI = GUICreate("ListView Set Item Image", 200, 200, -1, -1, BitOR($WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_SIZEBOX) )
;Create ListView
Global $hListView = GUICtrlCreateListView("", 10, 10, 180, 160, $LVS_NOCOLUMNHEADER)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
; Setup Image List
$hImage = _GUIImageList_Create()
_GUIImageList_AddBitmap($hImage, "red.bmp")
_GUIImageList_AddBitmap($hImage, "yellow.bmp")
_GUICtrlListView_SetImageList($hListView, $hImage, 2)
; Add Columns
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1");, 0)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1");, 0)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1");, 2)

;Activate Change Blocking and try to change items
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlListView_SetItemText($hListView, 0, "test change")
_GUICtrlListView_SetItemStateImage($hListView, 0, 1)
_GUICtrlListView_SetItemStateImage($hListView, 1, 2)
_GUICtrlListView_SetItemStateImage($hListView, 2, 1)

GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

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_ITEMCHANGING
                    Return 1
                Case $LVN_BEGINDRAG
                    Return 1
            EndSwitch
    EndSwitch   
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Figured out how to get some additional info in the help file.

I was able to figure out the "NewState" parameter = 4096 * "image index#" when changeing the state image of an item.

I'm only using 3 images so I check for these 3 numbers which will only allow those changes.

Case $LVN_ITEMCHANGING
    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
    $State = DllStructGetData($tInfo, "NewState")
    If $State <> 4096 AND $State <> 8192 AND $State <> 12288 Then Return 1

Hopefully that one should save someone some time.

Thanks,

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...