81206954 发表于 2009-12-27 18:12:05

如何制作这样的一个下载列表GUICtrlCreateListView

本帖最后由 81206954 于 2009-12-28 14:53 编辑

需要实现成这样效果图:


问题:原本的双击既可下载,就是不知道如何添加动态的下载信息在列表,和上面的图一样~~~

文件:1ListView_Progress.au3#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <ProgressConstants.au3>
#include <HeaderConstants.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>

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

Global $aProgress

GUIRegisterMsg($WM_NOTIFY, "_ListView_Notify")
GUIRegisterMsg($WM_SIZE, "_ListView_Notify")

; #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 - 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)
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)
   
    Local $iStyle = _WinAPI_GetWindowLong($sHwnd, $GWL_STYLE)
   
        If BitAND($iStyle, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
                _WinAPI_SetWindowLong($sHwnd, $GWL_STYLE, BitOR($iStyle, $WS_CLIPCHILDREN))
        EndIf
   
        Local $aRect
       
        If $sSubItemIndex = 0 Then
                $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
        Else
                $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
        EndIf
       
    $aProgress += 1
    ReDim $aProgress[$aProgress + 1]
    $aProgress[$aProgress] = _Progress_Create($sHwnd, $aRect, $aRect, $aRect - $aRect, $aRect - $aRect)
       
    $aProgress[$aProgress] = $sItemIndex
    $aProgress[$aProgress] = $sSubItemIndex
    $aProgress[$aProgress] = $sHwnd
       
    Return $aProgress[$aProgress]
EndFunc   ;==>_ListView_InsertProgressBar

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 _ListView_Notify($hWnd, $Msg, $wParam, $lParam)
        If $Msg = $WM_SIZE Then
                _WinAPI_InvalidateRect($hWnd)
                Return $GUI_RUNDEFMSG
        EndIf
       
    Local $tNMHEADER, $hWndFrom, $iCode, $i
   
    $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    $hWndFrom = DllStructGetData($tNMHEADER, "hwndFrom")
        $iCode = DllStructGetData($tNMHEADER, "Code")
   
        Switch $iCode
                Case $HDN_ITEMCHANGED, $HDN_ITEMCHANGEDW, $LVN_ENDSCROLL
                        If $iCode <> $LVN_ENDSCROLL Then $hWndFrom = _WinAPI_GetParent($hWndFrom)
                       
                        For $i = 1 To $aProgress
                                If $aProgress[$i] = $hWndFrom Then _
                                _MoveProgress($hWndFrom, $aProgress[$i], $aProgress[$i], $aProgress[$i])
                        Next
                       
                        _WinAPI_InvalidateRect($hWndFrom)
        EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_ListView_Notify

Func _MoveProgress($hListView, $hProgress, $sItemIndex, $sSubItemIndex)
        Local $aRect
       
        If $sSubItemIndex = 0 Then
                $aRect = _GUICtrlListView_GetItemRect($hListView, $sItemIndex, 2)
        Else
                $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
        EndIf
       
        If $aRect < 10 Then
      _WinAPI_ShowWindow($hProgress, $SW_HIDE)
    ElseIf $aRect >= 10 Then
      _WinAPI_ShowWindow($hProgress, $SW_SHOW)
    EndIf
       
    _WinAPI_MoveWindow($hProgress, $aRect, $aRect, $aRect - $aRect, $aRect - $aRect, True)
EndFunc   ;==>_MoveProgress

; #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 progressbar
;                  +to use its default progress indicator bar color.
; Return values .: Success      - The previous progress indicator bar color, or CLR_DEFAULT if the progress indicatorbarcolor
;                  +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

; #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

; #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 touseits
;                  +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

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

; 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

; #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

; #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 $aTmpArr
   
    For $i = 1 To $aProgress
      If $aProgress[$i] <> $hWnd Then
            $aTmpArr += 1
            ReDim $aTmpArr[$aTmpArr+1]
            
            $aTmpArr[$aTmpArr] = $aProgress[$i]
            $aTmpArr[$aTmpArr] = $aProgress[$i]
            $aTmpArr[$aTmpArr] = $aProgress[$i]
            $aTmpArr[$aTmpArr] = $aProgress[$i]
      EndIf
    Next
   
    $aProgress = $aTmpArr
   
    Local $aResult = DllCall("User32.dll", "int", "DestroyWindow", "hwnd", $hWnd)
    If @error Then Return SetError(1, 0, 0)
   
    Return $aResult <> 0
EndFunc文件:XXX.au3#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#Include <GuiComboBox.au3>
#include '1ListView_Progress.au3'

Global $iProgress = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 380, 210, -1, -1)
$ListView1 = GUICtrlCreateListView("序|      名 称   |          地址   |       进 度    |", 8, 8, 365, 161)
$item1 = GUICtrlCreateListViewItem("1|iis5.1xp(环境).rar|http://www.xinoa.cn/cmsTemplate/iis5.1xp(环境).rar|", $ListView1)
$item2 = GUICtrlCreateListViewItem("2|IISXPSP3.rar|http://down.ydaima.com/ruanjian/IISXPSP3.rar|", $ListView1)
$hProgress1= _ListView_InsertProgressBar($ListView1, 0, 3)
$hProgress2= _ListView_InsertProgressBar($ListView1, 1,3)

$Button1 = GUICtrlCreateButton("退出", 192, 176, 73, 22)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
_GetPos()
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button1
   Exit
EndSwitch
WEnd

Func _GetPos()
Local $sShareIP
$a = GUIGetCursorInfo($Form1)
If GUICtrlRead($ListView1) <> 0 And $a = 1 And $a = $ListView1 Then
MylBytesbbx()
ElseIf GUICtrlRead($ListView1) <> 0 And $a = 1 And $a = $ListView1 Then
MsgBox(0,"","这是右键点击发生的事件2")
EndIf
EndFunc   ;==>_GetPos



Func MylBytesbbx()
dim $Size,$i,$RemoteFile,$LoadFile,$File,$DownStatus,$IniStr,$begin,$dif, _
$g_szVersion ,$s,$s1,$s3;;;;;;;;;;;;;;;;全局变量
Dim $Formd       
$days = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), "|")
$RemoteFile=$days ;取得下载地址
$File=StringSplit($RemoteFile,'/',1)
$LoadFile=@ScriptDir&"\"&$File
ConsoleWrite($File)
ConsoleWrite($LoadFile)
$Size=InetGetSize($RemoteFile)
$begin = TimerInit()
InetGet($RemoteFile,$LoadFile,1,1)

for $i=int(@InetGetBytesRead/$Size*100) to 100
        sleep(500)
        if -1=@InetGetBytesRead then Exit
        $i=@InetGetBytesRead/$Size*100
                        if 1=@InetGetActive then
                                $DownStatus=""
                        Else
                                $DownStatus="没下载.."
                        EndIf
                        $dif = TimerDiff($begin)
                        $s=Round($dif/1000,0)
                        $s1=MylBytes(@InetGetBytesRead)
                        $s3=MylBytes(@InetGetBytesRead/$s)
;ProgressSet($i," 进度: "&int($i)&"%"&@CRLF&@CRLF&" 已下载" &$s1& " 总共" & MylBytes($Size),"正在下载,请稍后......" )
if $days=1 Then
        _Progress_SetPos($hProgress1, $i)
elseif $days=2 Then
        _Progress_SetPos($hProgress2, $i)
else
endif
        Next               
        ProgressSet($i, " 完成下载 100%")
        ProgressOff()

EndFunc

Func MylBytes($lBytes)
;下载文件
                        if $lBytes<1024 Then
                                                Return ($lBytes & "b")
                                        ElseIf $lBytes<1048576 Then
                                                Returnint(($lBytes / 1024)) &"k"
                                        ElseIf$Lbytes<536870912 Then
                                                ReturnRound($lBytes / 1024 / 1024,2)&"M"
                                        Else
                                                Return Round($lBytes/(1024^2) / 1024,2) & "G"
                                EndIf
EndFuncsanmoking虽然超50行,但是重点的文件是这个XXX.au3,1ListView_Progress.au3这个文件不用改动,完整代码只是为了方便你们测试
             Func _GetPos() 这个是鼠标双击后获取GUICtrlCreateListViewItem项的值这个也不用改完整的
             Func MylBytes($lBytes)这个是判断并设置文件大小,这个也不用改是完整的

             Func MylBytesbbx() 下载代码

主要是这个下载列表的问题
                  GUICtrlCreateListViewItem

我数了数,主要要看的代码也没50行啊 :face (33):
各位帮帮忙我想实现这个效果(看最顶的图)

sanmoking 发表于 2009-12-28 09:25:04

看到超50行的代码就膜拜一下
页: [1]
查看完整版本: 如何制作这样的一个下载列表GUICtrlCreateListView