Besserer ListView Check

  • Wie kann ich akkurater die Spalte eines ListViews auslesen, als $LVN_ITEMCHANGED zu benutzen, da $LVN_ITEMCHANGED mehrmals aufgerufen wird?

    Hier das Beispiel aus der Hilfe:

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hListView

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Local $GUI, $hImage
    $GUI = GUICreate("(UDF Created) ListView Create", 200, 300)

    [/autoit] [autoit][/autoit] [autoit]

    $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    $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_KEYDOWN ; A key has been pressed
    ConsoleWrite("$LVN_KEYDOWN" & @CRLF)
    ; No return value
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    ConsoleWrite("$NM_CLICK" & @CRLF)
    Case $LVN_ITEMCHANGED ; An item has changed
    ConsoleWrite("$LVN_ITEMCHANGED" & @CRLF)
    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Wenn eine Zelle markiere und mit den Cursor Tasten die Auswahl bewege, dann wird $LVN_ITEMCHANGED leider mehrmals aufgerufen!
    Ich will prüfen, welche Zelle gerade aufgerufen wurde. Mit $LVN_KEYDOWN geht es auch, aber ich bekomme nicht die Zelle und deren Inhalt raus!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    2 Mal editiert, zuletzt von UEZ (7. Januar 2011 um 22:16)

    • Offizieller Beitrag

    Damit schlage ich mich auch gerade rum. ?(
    Eine Lösung per WM_NOTIFY habe ich auch nicht parat, nur eine Alternative:

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hListView, $hDummy

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Local $GUI, $hImage, $iItem
    $GUI = GUICreate("(UDF Created) ListView Create", 200, 300)

    [/autoit] [autoit][/autoit] [autoit]

    $hDummy = GUICtrlCreateDummy()

    [/autoit] [autoit][/autoit] [autoit]

    $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    GUIDelete()
    Return
    Case $hDummy
    $iItem = ControlListView($GUI, '', $hListView, 'GetSelected')
    ConsoleWrite('Item: ' & $iItem & @CR)
    EndSwitch
    WEnd
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    $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_KEYDOWN ; A key has been pressed
    ConsoleWrite("$LVN_KEYDOWN" & @CRLF)
    GUICtrlSendToDummy($hDummy)
    ; No return value
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    ConsoleWrite("$NM_CLICK" & @CRLF)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
  • ich hoffe dir helfen die beiden Funktionen (zumindest zum Auslesen) ein bisschen weiter:

    [autoit]


    _GUICtrlListView_GetSelectedIndices
    _GUICtrlListView_GetItemText

    [/autoit]

    PS: ich bin mir nicht sicher ob ich es richtig verstanden habe

    • Offizieller Beitrag

    Probier mal das :

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

    [/autoit] [autoit][/autoit] [autoit]

    Global $hListView

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Local $GUI, $hImage
    $GUI = GUICreate("(UDF Created) ListView Create", 200, 300)

    [/autoit] [autoit][/autoit] [autoit]

    $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case -12
    Local $iSel= ControlListView("(UDF Created) ListView Create", "", $hWndListView, "GetSelected", 1)
    Local $sCurSel = _GUICtrlListView_GetItemText($hWndListView,$iSel)
    ConsoleWrite("Index :"&$iSel& @CRLF)
    ConsoleWrite("Inhalt :"&$sCurSel & @CRLF)
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    ConsoleWrite("$NM_CLICK" & @CRLF)
    Case $NM_KILLFOCUS ; An item has changed
    ConsoleWrite("$LVN_ITEMCHANGED" & @CRLF)
    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG

    [/autoit]

    Edit: Keine gute Lösung $NM_Customdraw abzufangen. :(

  • Hab' ein Workaround gefunden, indem ich ein bissl bei Oscar in seinem FileCommander abgeschaut habe (vielen Dank OSCAR!)! :whistling:

    Hier der Auszug:

    [autoit]


    Case $LVN_KEYDOWN
    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
    Switch DllStructGetData($tInfo, 'VKey')
    Case 38
    $index = _GUICtrlListView_GetSelectionMark($List) - 1
    If $index > -1 Then Make_Screenshot(_GUICtrlListView_GetItemText($List, $index, 1), $aWnd[$index][2], $aWnd[$index][3])
    Case 40
    $index = _GUICtrlListView_GetSelectionMark($List) + 1
    If $index < _GUICtrlListView_GetItemCount($hListView) Then Make_Screenshot(_GUICtrlListView_GetItemText($List, $index, 1), $aWnd[$index][2], $aWnd[$index][3])
    EndSwitch
    EndSwitch

    [/autoit]

    Und zwar ist der Code für meinen AutoIt Windows Screenshooter!

    Vielen Dank für eurer Feedback!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Listviews sind sehr großzügig was Notifications angeht :)...

    [autoit]

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

    [/autoit][autoit][/autoit][autoit]

    Opt('MustDeclareVars', 1)

    [/autoit][autoit][/autoit][autoit]

    $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

    [/autoit][autoit][/autoit][autoit]

    Global $hListView

    [/autoit][autoit][/autoit][autoit]

    _Main()

    [/autoit][autoit][/autoit][autoit]

    Func _Main()

    [/autoit][autoit][/autoit][autoit]

    Local $GUI, $hImage
    $GUI = GUICreate("(UDF Created) ListView Create", 200, 300)

    [/autoit][autoit][/autoit][autoit]

    $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit][autoit][/autoit][autoit]

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    [/autoit][autoit][/autoit][autoit]

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    [/autoit][autoit][/autoit][autoit]

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

    [/autoit][autoit][/autoit][autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    [/autoit][autoit][/autoit][autoit]

    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)

    [/autoit][autoit][/autoit][autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    [/autoit][autoit][/autoit][autoit]

    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Local $iItem = DllStructGetData($tInfo, "Item")
    Local $iSubItem = DllStructGetData($tInfo, "SubItem")
    Local $iNewState = DllStructGetData($tInfo, "NewState")
    Local $iOldState = DllStructGetData($tInfo, "OldState")
    Local $iChanged = DllStructGetData($tInfo, "Changed")
    Local $iActionX = DllStructGetData($tInfo, "ActionX")
    Local $iActionY = DllStructGetData($tInfo, "ActionY")
    Local $iParam = DllStructGetData($tInfo, "Param")

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $LVN_ITEMACTIVATE ; Doubleclick
    ; $tagNMITEMACTIVATE
    ConsoleWrite("$LVN_ITEMACTIVATE" & @CRLF)
    $tINFO = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

    [/autoit][autoit][/autoit][autoit]

    Case $LVN_KEYDOWN ; A key has been pressed
    ConsoleWrite("$LVN_KEYDOWN" & @CRLF)
    ; No return value
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    ConsoleWrite("$NM_CLICK" & @CRLF)

    [/autoit][autoit][/autoit][autoit]

    Case $LVN_ITEMCHANGED ; An item has changed
    ConsoleWrite("LVN_ITEMCHANGED" & @tab & "Item: " & $iItem & @tab & "SubItem: " & $iSubItem & @tab & "NewState: " & $iNewState & @tab & "OldState: " & $iOldState & @tab & "Changed: " & $iChanged & @tab & "ActionX: " & $iActionX & @tab & "ActionY: " & $iActionY & @tab & "Param: " & $iParam & @crlf)

    [/autoit][autoit][/autoit][autoit]

    Case $LVN_HOTTRACK
    ConsoleWrite("LVN_HOTTRACK" & @tab & "Item: " & $iItem & @tab & "SubItem: " & $iSubItem & @tab & "NewState: " & $iNewState & @tab & "OldState: " & $iOldState & @tab & "Changed: " & $iChanged & @tab & "ActionX: " & $iActionX & @tab & "ActionY: " & $iActionY & @tab & "Param: " & $iParam & @crlf)

    [/autoit][autoit][/autoit][autoit]

    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    • Offizieller Beitrag

    Die Dummylösung ist genial :thumbup:
    Vor lauter Notify geschnüffel kommt man nicht auf das einfachste. 8|

    KaFu $LVN_ITEMCHANGED war keine Option, die Notify wird zu oft ausgelöst. ;)

  • Hi KaFu,

    nett, dass du dein Wissen auch hier teilst! :thumbup:

    Weiter so :!:

    Gruß,
    UEZ ;)

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Ja, im FileCommander habe ich diesen Workaround eingebaut. Wobei ich damit auch nicht wirklich zufrieden bin.
    Ich glaube, mir gefällt die Lösung mit dem Dummy-Control (Post#2) besser. :)

    Die ist echt clever, nur für mein Code nicht von Nutzen. Siehst du, wenn du mal in den Code reinschaust!

    Edit: obwohl, könnte man auch so implementieren! :D

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • KaFu $LVN_ITEMCHANGED war keine Option, die Notify wird zu oft ausgelöst. ;)


    Per $LVN_HOTTRACK das Item in eine globale Variable schreiben und diese dann im $LVN_KEYDOWN Event verwenden ;)?

    Hi KaFu, nett, dass du dein Wissen auch hier teilst! :thumbup:


    Deine und eukalyptus Postings im internationalen Forum haben mich her gelockt :thumbup:...

    • Offizieller Beitrag
    Zitat

    Per $LVN_HOTTRACK das Item in eine globale Variable schreiben und diese dann im $LVN_KEYDOWN Event verwenden ;)?

    Ok, ich nehm alles zurück und behaupte das Gegenteil :D