_GUICtrlListView Fragen

  • Hiho,

    mein aktuelles script ist folgendes:
    es ist dafür gedacht, um schnell existierende fenster "On Top" zu setzen, oder dieses attribut wieder zu löschen (funzt nur noch nicht *g*)
    nun habe ich 2 fragen:

    1. wie funzt _GUICtrlListView_SimpleSort? mit der hilfe bin ich leider nicht weiter gekommen, wie müsste es in meinem fall aussehen?
    2. wie bekomme ich es hin, dass bei einem doppelklick auf eine item im ListView eine Funktion ausgeführt wird ?

    PS: ok, mit dem doppelklick scheint was kompliziert zu sein, kann man dann ne reaktion anfordern, sobald ein item markiert wird?
    habe nen button, der soll dann, je nachdem welches item angeklickt wird, ein anderes label haben.

    PPS: soweit feritg =)

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    #include <Process.au3>
    #include <File.au3>
    #include <GUIConstants.au3>
    #Include <GuiListView.au3>

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

    Opt("OnExitFunc", "endscript")
    Opt("GUIOnEventMode", 1)

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

    Global $var2
    Global $WinList
    Global $ini = @scriptdir & "\ActiveWin.ini"

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

    $Form1 = GUICreate("active Windows", 308, 312, 0, 0, "", $WS_EX_TOOLWINDOW )
    GUISetOnEvent($GUI_EVENT_CLOSE, "endscript")
    $Button1 = GUICtrlCreateButton("Set on Top or Back", 0,0,300,20)
    GUICtrlSetOnEvent(-1, "_SetOnTop")
    $ListView1 = _GUICtrlListView_Create ($Form1, "", 0, 20, 300, 250)
    GUICtrlSetOnEvent(-1, "_SetOnTop")
    _GUICtrlListView_SetExtendedListViewStyle ($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
    _GUICtrlListView_InsertColumn ($ListView1, 0, "Process", 80)
    _GUICtrlListView_InsertColumn ($ListView1, 1, "Window", 180)
    _GUICtrlListView_InsertColumn ($ListView1, 2, "Top", 40)
    $Button2 = GUICtrlCreateButton("Update", 0, 271, 300, 20, 0)
    GUICtrlSetOnEvent(-1, "_Update")

    GUISetState(@SW_SHOW)
    WinSetOnTop($Form1,'',1)
    WinSetTrans($Form1,'', 220)

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

    _update()

    While 1
    Sleep(100)
    WEnd

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

    Func _Update()
    If FileExists($ini) Then
    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $ReadOnTop = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $ReadOnTop[0][0]
    WinSetOnTop($ReadOnTop[$e][0], "", 0)
    Next
    EndIf
    IniDelete($ini, $Sections[$i])
    Next
    EndIf
    EndIf

    _GUICtrlListView_DeleteAllItems($ListView1)

    $var = WinList()
    For $i = 1 to $var[0][0]
    If Not @error Then
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    $ProcessName = _ProcessGetName(WinGetProcess($var[$i][0]))
    If $ProcessName = @ScriptName Then
    Else
    IniWriteSection($ini, $ProcessName, "")
    IniWrite($ini, $ProcessName, $var[$i][0], "")
    EndIf
    EndIf
    EndIf
    Next

    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $Section = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $Section[0][0]
    _GUICtrlListView_AddItem($ListView1, $Sections[$i])
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $Section[$e][0], 1)
    Next
    EndIf
    Next
    EndIf

    WinSetOnTop($Form1,'',1)

    EndFunc

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

    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc

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

    Func _SetOnTop()
    For $i = 1 To _GUICtrlListView_GetItemCount($ListView1)
    $Checked = _GUICtrlListView_GetItemChecked($ListView1, $i - 1)
    If $Checked = True Then
    $Sec = _GUICtrlListView_GetItemText($ListView1, $i - 1)
    $key = _GUICtrlListView_GetItemText($ListView1, $i - 1, 1)
    $ReadOnTop = IniRead($ini, $Sec, $key, "")
    If $ReadOnTop = "" Then
    WinActivate($key)
    WinSetOnTop($key, "", 1)
    IniWrite($ini, $Sec, $key, "x")
    _GUICtrlListView_AddSubItem($ListView1, $i -1, "x", 2)
    Else
    WinSetOnTop($key, "", 0)
    WinSetState($key, "", @sw_minimize)
    IniWrite($ini, $Sec, $key, "")
    _GUICtrlListView_AddSubItem($ListView1, $i -1, "", 2)
    EndIf
    EndIf
    Next
    For $i = 1 To _GUICtrlListView_GetItemCount($ListView1)
    _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next

    WinSetOnTop($Form1,'',1)

    EndFunc

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

    Func endscript()
    If FileExists($ini) Then
    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $ReadOnTop = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $ReadOnTop[0][0]
    WinSetOnTop($ReadOnTop[$e][0], "", 0)
    Next
    EndIf
    IniDelete($ini, $Sections[$i])
    Next
    EndIf
    EndIf
    Exit
    EndFunc

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

    ;~ Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

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

    ;~ $title = "Microsoft Excel - Mappe1"

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

    ;~ WinSetOnTop($title, "", 0)

    [/autoit]
  • Hi,
    1. schau dir mal dieses Help File im Übersetzungsstatus links an. Dort habe ich es ins deutsche übersetzt. Vielleicht verstehts du es dann besser ;)
    2. schau dir die Hilfe zu _GUICtrlListView_Create mal an (das Beispiel, dort wird auch ein Doppelklick aufgeführt)
    :D

  • dank dir tweaky, werd ich machen.
    hab aber grad noch ne aktuelle frage:

    und zwar würde ich die einträge gerne sortieren lassen. das geht ja via control style.
    ich habe jedoch 3 spalten. jedoch wird, wenn ich den sortier-style nutze, in spalte 2 nur
    der erste und letzte eintrag angezeigt. und das auch noch falsch, da die nicht mehr zu
    dem eintrag aus spalte 1 passen. jmd nen plan?

    Spoiler anzeigen
    [autoit]

    #NoTrayIcon

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

    #include <array.au3>
    #include <Process.au3>
    #include <File.au3>
    #include <GUIConstants.au3>
    #Include <GuiListView.au3>

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

    Opt("WinTitleMatchMode", 2)
    Opt("OnExitFunc", "endscript")
    Opt("GUIOnEventMode", 1)

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

    Global $var2
    Global $WinList
    Global $ini = @scriptdir & "\ActiveWin.ini"
    Global $inio = @scriptdir & "\ActiveWinOld.ini"

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

    HotKeySet("^!0", "HiDE")

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

    $Form1 = GUICreate("active Windows", 308, 312, 0, 0, "", $WS_EX_TOOLWINDOW )
    GUISetOnEvent($GUI_EVENT_CLOSE, "endscript")
    $Button1 = GUICtrlCreateButton("Set on Top or Back", 0,0,300,20)
    GUICtrlSetOnEvent(-1, "_SetOnTop")
    $ListView1 = _GUICtrlListView_Create ($Form1, "", 0, 20, 300, 250, $LVS_REPORT + $LVS_SINGLESEL + $LVS_SHOWSELALWAYS + $WS_CHILD + $WS_VISIBLE + $LVS_SORTASCENDING)
    GUICtrlSetOnEvent(-1, "_SetOnTop")
    _GUICtrlListView_SetExtendedListViewStyle ($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_TWOCLICKACTIVATE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_BORDERSELECT ))
    _GUICtrlListView_InsertColumn ($ListView1, 0, "Process", 80)
    _GUICtrlListView_InsertColumn ($ListView1, 1, "Window", 180)
    _GUICtrlListView_InsertColumn ($ListView1, 2, "Top", 40)
    $Button2 = GUICtrlCreateButton("Update", 0, 271, 300, 20, 0)
    GUICtrlSetOnEvent(-1, "_Update")

    GUISetState(@SW_SHOW)
    WinSetOnTop($Form1,'',1)
    WinSetTrans($Form1,'', 220)

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

    _update()

    While 1
    Sleep(100)
    WEnd

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

    Func _Update()
    If FileExists($ini) Then
    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $ReadOnTop = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $ReadOnTop[0][0]
    WinSetOnTop($ReadOnTop[$e][0], "", 0)
    Next
    EndIf
    IniDelete($ini, $Sections[$i])
    Next
    EndIf
    EndIf

    _GUICtrlListView_DeleteAllItems($ListView1)

    $var = WinList()
    For $i = 1 to $var[0][0]
    If Not @error Then
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    $ProcessName = _ProcessGetName(WinGetProcess($var[$i][0]))
    If $ProcessName = @ScriptName Then
    Else
    IniWriteSection($ini, $ProcessName, "")
    IniWrite($ini, $ProcessName, $var[$i][0], "")
    EndIf
    EndIf
    EndIf
    Next

    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $Section = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $Section[0][0]
    _GUICtrlListView_AddItem($ListView1, $Sections[$i])
    _GUICtrlListView_AddSubItem($ListView1, _GUICtrlListView_GetItemCount($ListView1) - 1, $Section[$e][0], 1)
    Next
    EndIf
    Next
    EndIf

    WinSetOnTop($Form1,'',1)

    EndFunc

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

    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf
    EndFunc

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

    Func _SetOnTop()
    For $i = 1 To _GUICtrlListView_GetItemCount($ListView1)
    $Checked = _GUICtrlListView_GetItemChecked($ListView1, $i - 1)
    If $Checked = True Then
    $Sec = _GUICtrlListView_GetItemText($ListView1, $i - 1)
    $key = _GUICtrlListView_GetItemText($ListView1, $i - 1, 1)
    $ReadOnTop = IniRead($ini, $Sec, $key, "")
    If $ReadOnTop = "" Then
    WinActivate($key)
    WinSetOnTop($key, "", 1)
    IniWrite($ini, $Sec, $key, "x")
    _GUICtrlListView_AddSubItem($ListView1, $i -1, "x", 2)
    Else
    WinSetOnTop($key, "", 0)
    WinSetState($key, "", @sw_minimize)
    IniWrite($ini, $Sec, $key, "")
    _GUICtrlListView_AddSubItem($ListView1, $i -1, "", 2)
    EndIf
    EndIf
    Next
    For $i = 1 To _GUICtrlListView_GetItemCount($ListView1)
    _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next

    WinSetOnTop($Form1,'',1)

    EndFunc

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

    Func endscript()
    If FileExists($ini) Then
    $Sections = IniReadSectionNames($ini)
    If Not @error Then
    For $i = 1 To $Sections[0]
    $ReadOnTop = IniReadSection($ini, $Sections[$i])
    If Not @error Then
    For $e = 1 To $ReadOnTop[0][0]
    WinSetOnTop($ReadOnTop[$e][0], "", 0)
    Next
    EndIf
    IniDelete($ini, $Sections[$i])
    Next
    EndIf
    FileDelete($inio)
    EndIf

    Exit
    EndFunc

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

    Func HiDE()
    $State = WinGetState($Form1)
    If $State = 15 Or $State = 7 Then
    WinSetState($Form1, "", @sw_minimize)
    ElseIf $State = 23 Then
    WinSetState($Form1, "", @SW_RESTORE)
    Else
    WinSetState($Form1, "", @SW_RESTORE)
    EndIf
    EndFunc
    ;~ Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

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

    ;~ $title = "Microsoft Excel - Mappe1"

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

    ;~ WinSetOnTop($title, "", 0)

    [/autoit]
    • Offizieller Beitrag

    Hi,
    hier mal ein Bsp. für einfache Sortierung durch Spaltenklick (kannst das natürlich auch anders auslösen).
    Hab auch mal das Auslesen des Inhalts eines angeklickten Spaltenwertes eingefügt.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <GUIListView.au3>

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

    $gui = GUICreate('test')
    $hListView = GUICtrlCreateListView('Spalte1|Spalte2', 10, 10, 300, 200)
    _GUICtrlListView_SetColumnWidth(-1, 0, 148)
    _GUICtrlListView_SetColumnWidth(-1, 1, 148)
    For $i = 65 To 75
    GUICtrlCreateListViewItem('Zeile ' & Chr($i) & ' - Spalte 1|Zeile ' & Chr($i) & ' - Spalte 2', $hListView)
    Next
    GUISetState()

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

    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount ($hListView) ]
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

    Do
    $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

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

    Func _LeftClick($Info)
    MsgBox(0, 'Text in Spalte ' & $Info[4]+1, _GUICtrlListView_GetItemText($Info[1], $Info[3], $Info[4]) )
    EndFunc

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $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_COLUMNCLICK ; A column was clicked
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    _GUICtrlListView_SimpleSort ($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
    Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $aInfo[12] = [$hWndFrom, _
    $iIDFrom, _
    $iCode, _
    DllStructGetData($tInfo, "Index"), _
    DllStructGetData($tInfo, "SubItem"), _
    DllStructGetData($tInfo, "NewState"), _
    DllStructGetData($tInfo, "OldState"), _
    DllStructGetData($tInfo, "Changed"), _
    DllStructGetData($tInfo, "ActionX"), _
    DllStructGetData($tInfo, "ActionY"), _
    DllStructGetData($tInfo, "lParam"), _
    DllStructGetData($tInfo, "KeyFlags")]
    _LeftClick($aInfo)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]