Listview mit Progressbar in ListViewItems

  • und jetzt die große Frage: ist das möglich?
    Ich habe eine Warteschlange, mit Aufgaben. (Downloads-Manager)

    Die Listview soll dann Beschreibung, verbleibende Zeit, und eine Progressbar im ListViewItem haben.

    Ich hab schon den Thread hier gefunden:
    http://www.autoitscript.com/forum/index.php?showtopic=64091

    Aber das Script, welches dort verlinkt wird (http://www.autoitscript.com/forum/index.php?showtopic=44132)
    ist schon total veraltet und ich schaffs nichtmal das ganze lauffähig zu bekommen. :S

    Wäre nett, wenn da jemand einen Tipp für mich hat

    PS: Hier gibts noch ein C# und ein VB Beispiel:
    http://www.autoitscript.com/forum/index.php?showtopic=64091&view=findpost&p=478151

    :hail:

  • Jap, hat funktioniert.
    Ich hab die Funktion noch ein bisschen abgeändert, weil ich das Treeview-Notify erstmal nicht brauchte.

    Außerdem werden die Progressbars jetzt im alten Windows Style erstellt. So kann ich das ganze noch nach belieben einfärben.

    Spoiler anzeigen
    [autoit]

    #include <Constants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <ProgressConstants.au3>
    #include <SendMessage.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

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

    Global Const $SW_HIDE = 0
    Global Const $SW_SHOW = 5

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

    Opt('MustDeclareVars', 1)

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

    _Main()

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

    Func _Main()
    Local $listview
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

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

    GUICreate("ImageList Add", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState()

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

    ; Load images

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

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "Items", 120)
    ; Add items
    _GUICtrlListView_AddItem($listview, "Item 1")
    _GUICtrlListView_AddItem($listview, "Item 2")
    _GUICtrlListView_AddItem($listview, "Item 3")

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

    Local $hProgress = _ListView_InsertProgressBar($listview, 1)
    _Progress_SetBarColor($hProgress, 0x0000FF)
    _Progress_SetBkColor($hProgress,0x00FFFF)

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

    ; Loop until user exits
    Local $i
    Do
    _Progress_SetPos($hProgress, $i)
    $i += 1
    Sleep(100)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE Or $i = 101
    GUIDelete()
    EndFunc ;==>_Main

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

    ; #FUNCTION# ======================================================================================
    ; Function Name: _ListView_InsertProgressBar()
    ; Description: Inserts a progressbar control in the ListView control.
    ; Syntax.........: _ListView_InsertProgressBar($sHwnd, $sItemIndex[, $sSubItemIndex])
    ; Parameter(s): $sHwnd - Handle to the ListView control.
    ; $sItemIndex - Zero based index of the item at which the progressbar should be inserted.
    ; $sSubItemIndex - [Optional] One based index of the subitem where progressbar should be placed, default is 1.
    ;
    ; Return Value(s): Returns the identifier (controlID) of the new progressbar control.
    ; Requirement(s): AutoIt 3.2.10.0 and above
    ; Note(s): Optimal amount of progressbar controls is 5-10. Don`t abuse with many amount of progressbar controls.
    ;
    ; Author(s): R.Gilman (a.k.a rasim), arcker
    ;==================================================================================================
    Func _ListView_InsertProgressBar($sHwnd, $sItemIndex, $sSubItemIndex = 0)
    Local $hRet
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)

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

    Local $iStyle = _WinAPI_GetWindowLong($sHwnd, $GWL_STYLE)

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

    If BitAND($iStyle, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
    _WinAPI_SetWindowLong($sHwnd, $GWL_STYLE, BitOR($iStyle, $WS_CLIPCHILDREN))
    EndIf

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

    Local $aRect

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

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
    EndIf
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0)
    $hRet = _Progress_Create($sHwnd, $aRect[0], $aRect[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1])
    DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7)

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

    Return $hRet
    EndFunc ;==>_ListView_InsertProgressBar

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

    Func _Progress_Create($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = 0)
    $iStyle = BitOR($iStyle, $WS_CHILD, $WS_VISIBLE)
    Return _WinAPI_CreateWindowEx($iExStyle, "msctls_progress32", "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd)
    EndFunc ;==>_Progress_Create
    Func _MoveProgress($hListView, $hProgress, $sItemIndex, $sSubItemIndex)
    Local $aRect

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

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($hListView, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    EndIf

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

    If $aRect[1] < 10 Then
    _WinAPI_ShowWindow($hProgress, $SW_HIDE)
    ElseIf $aRect[1] >= 10 Then
    _WinAPI_ShowWindow($hProgress, $SW_SHOW)
    EndIf

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

    _WinAPI_MoveWindow($hProgress, $aRect[0], $aRect[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1], True)
    EndFunc ;==>_MoveProgress

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

    ; #FUNCTION# ====================================================================================================
    ; Description ...: Sets the color of the indicator bar
    ; Parameters ....: $hWnd - Handle to the control
    ; $iColor - The new progress indicator bar color. Specify the CLR_DEFAULT value to cause the progress bar
    ; +to use its default progress indicator bar color.
    ; Return values .: Success - The previous progress indicator bar color, or CLR_DEFAULT if the progress indicator bar color
    ; +is the default color.
    ; Author ........: Paul Campbell (PaulIA), Updated By Arcker
    ; Remarks .......: This message is supported only in the Windows Classic theme
    ; Related .......:
    ; ====================================================================================================
    Func _Progress_SetBarColor($hWnd, $iColor)
    Return _SendMessage($hWnd, $PBM_SETBARCOLOR, 0, $iColor)
    EndFunc ;==>_Progress_SetBarColor

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

    ; #FUNCTION# ====================================================================================================
    ; Description ...: Sets the current position
    ; Parameters ....: $hWnd - Handle to the control
    ; $iPos - The new position
    ; Return values .: Success - The previous position
    ; Author ........: Paul Campbell (PaulIA), Updated By Arcker
    ; Remarks .......:
    ; Related .......: _Progress_GetPos
    ; ====================================================================================================
    Func _Progress_SetPos($hWnd, $iPos)
    Return _SendMessage($hWnd, $PBM_SETPOS, $iPos, 0)
    EndFunc ;==>_Progress_SetPos

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

    ; #FUNCTION# ====================================================================================================
    ; Description ...: Sets the background color in the progress bar
    ; Parameters ....: $hWnd - Handle to the control
    ; $iColor - The new background color. Specify the CLR_DEFAULT value to cause the progress bar to use its
    ; +default background color.
    ; Return values .: Success - The previous background color, or CLR_DEFAULT if the background color is the default color.
    ; Author ........: Paul Campbell (PaulIA), Updated By Arcker
    ; Remarks .......: This message is supported only in the Windows Classic theme
    ; Related .......:
    ; ====================================================================================================
    Func _Progress_SetBkColor($hWnd, $iColor)
    Return _SendMessage($hWnd, $PBM_SETBKCOLOR, 0, $iColor)
    EndFunc ;==>_Progress_SetBkColor

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

    ; #FUNCTION# ====================================================================================================

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

    ; Description ...: Specifies the step increment
    ; Parameters ....: $hWnd - Handle to the control
    ; $iStep - Step increment.
    ; Return values .: Success - The previous step increment
    ; Author ........: Paul Campbell (PaulIA)
    ; Remarks .......: The step increment is the amount by which the progress bar increases its current position whenever you use the
    ; _Progress_StepIt function. By default, the step increment is set to 10.
    ; Related .......: _Progress_StepIt
    ; ====================================================================================================
    Func _Progress_SetStep($hWnd, $iStep = 10)
    Return _SendMessage($hWnd, $PBM_SETSTEP, $iStep, 0)
    EndFunc ;==>_Progress_SetStep

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

    ; #FUNCTION# ====================================================================================================
    ; Description ...: Advances the current position by the step increment
    ; Parameters ....: $hWnd - Handle to the control
    ; Return values .: Success - The previous position
    ; Author ........: Paul Campbell (PaulIA), Updated By Arcker
    ; Remarks .......:
    ; Related .......: _Progress_SetStep
    ; ====================================================================================================
    Func _Progress_StepIt($hWnd)
    Return _SendMessage($hWnd, $PBM_STEPIT, 0, 0)
    EndFunc ;==>_Progress_StepIt

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

    ; #FUNCTION# ====================================================================================================
    ; Description ...: Delete the progressbar control
    ; Parameters ....: $hWnd - Handle to the control
    ; Return values .: Success - True
    ; Failure - False
    ; Author ........: G. Sandler (MrCreatoR), Updated by rasim
    ; Remarks .......:
    ; Related .......: _Progress_SetStep
    ; ====================================================================================================
    Func _Progress_Delete($hWnd)
    Local $aResult = DllCall("User32.dll", "int", "DestroyWindow", "hwnd", $hWnd)
    If @error Then Return SetError(1, 0, 0)

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

    Return $aResult[0] <> 0
    EndFunc ;==>_Progress_Delete

    [/autoit]